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 字符串'
}
}