Created
September 16, 2019 13:06
-
-
Save SeeminglyScience/c80ce61b18277b006eb56084bd7c7873 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CppHeaderFilePath = 'path/to/something.h' | |
$interfaceDefinition = Get-Content $CppHeaderFilePath -Raw | |
$flags = [Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance | |
$fields = @{ | |
_a = [guid].GetField('_a', $flags) | |
_b = [guid].GetField('_b', $flags) | |
_c = [guid].GetField('_c', $flags) | |
_d = [guid].GetField('_d', $flags) | |
_e = [guid].GetField('_e', $flags) | |
_f = [guid].GetField('_f', $flags) | |
_g = [guid].GetField('_g', $flags) | |
_h = [guid].GetField('_h', $flags) | |
_i = [guid].GetField('_i', $flags) | |
_j = [guid].GetField('_j', $flags) | |
_k = [guid].GetField('_k', $flags) | |
} | |
$sb = [Text.StringBuilder]::new() | |
$allMatches = [regex]::Matches($interfaceDefinition, 'MIDL_INTERFACE\("([a-fA-F0-9\-]+)"\)\s+(I\p{L}+)\p{Zs}') | | |
Sort-Object { $PSItem.Groups[2].Value } | |
$null = for ($i = 0; $i -lt $allMatches.Count; $i++) { | |
if ($i -ne 0) { | |
$sb.AppendLine().AppendLine(); | |
} | |
$guid = [guid]$allMatches[$i].Groups[1].Value | |
$sb.Append('public static readonly Guid '). | |
Append($allMatches[$i].Groups[2].Value). | |
Append(' = new Guid('). | |
AppendFormat('0x{0:X8}', $fields['_a'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X4}', $fields['_b'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X4}', $fields['_c'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_d'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_e'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_f'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_g'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_h'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_i'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_j'].GetValue($guid)). | |
Append(', '). | |
AppendFormat('0x{0:X2}', $fields['_k'].GetValue($guid)). | |
Append(');') | |
} | |
$sb.ToString() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment