Get-GUIDandDeclare

Get-GUIDandDeclare


把 _GUID_b5d30521_b5b3_4f9d_9748_5e3e1636e0bf 转换成 GUID 数据,顺便生成声明:

用法:

Get-GUIDandDeclare _GUID_b5d30521_b5b3_4f9d_9748_5e3e1636e0bf

Name                           Value
----                           -----
FullDeclare                    // b5d30521-b5b3-4f9d-9748-5e3e1636e0bf...
GUID                           b5d30521-b5b3-4f9d-9748-5e3e1636e0bf
Declare                        { 0xb5d30521, 0xb5b3, 0x4f9d, { 0x97, 0x48, 0x5e, 0x3e, 0x16, 0x36, 0xe0, 0xbf } }

或者

Get-GUIDandDeclare _GUID_b5d30521_b5b3_4f9d_9748_5e3e1636e0bf ABCD -Single

// b5d30521-b5b3-4f9d-9748-5e3e1636e0bf
const IID IID_ABCD = { 0xb5d30521, 0xb5b3, 0x4f9d, { 0x97, 0x48, 0x5e, 0x3e, 0x16, 0x36, 0xe0, 0xbf } };

function Get-GUIDandDeclare
{
 [CmdletBinding()]
 param
 (
  [Parameter(Mandatory = $true,
       Position = 1)]
  $GUIDstring,
  [Parameter(Position = 2)]
  $InterfaceName,
  [Parameter(Position = 3)]
  [switch]$Single
 )
 
 #TODO: Place script here
 $GUIDstringClean = $GUIDstring.replace('_GUID_', '').replace('GUID_', '').replace('_', '-').trim()
 $GUID = [System.Guid]$GUIDstringClean
 
 if ($GUID)
 {
  $GUIDArray = $guid -split ('-')
  $GUIDArray1 = ($GUIDArray)[0 .. 2] | %{ '0x' + $_ }
  $GUIDArray2 = ($guid.ToByteArray())[8 .. 16] | % { '0x' + $_.tostring('x2') }
  
  $GUIDDeclare = '{ ' + ($guidarray1 -join (', ')) + ', { ' + ($guidarray2 -join (', ')) + ' } }'
  $FullDeclare = '// ' + $GUID.ToString() + "`n" + 'const IID IID_' + $InterfaceName + ' = ' + $GUIDDeclare + ';'
  
  if (-not $InterfaceName)
  { $InterfaceName = ($GUIDArray)[3] + ($GUIDArray)[4] }
  if ($Single)
  { return $FullDeclare }
  else
  {
   return @{
    'GUID' = $GUID;
    'Declare' = $GUIDDeclare;
    'FullDeclare' = $FullDeclare
   }
  }
 }
 else
 {
  Write-Warning '不是正确的 GUID 字符串'
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值