日期:2014-05-16  浏览次数:21060 次

将vb调用api代码转换成c#
vb代码如下:
Public Declare Function RegOpenKeyEx Lib "ADVPAI32" Alias "RegOpenKeyExA" (ByVal hKey&,ByVal lpSubKey$,ByVal ulOptians&,ByVal samDesired&,phkResult&) as Long
转换成c#代码应该怎么写啊?
------解决方案--------------------
[DllImport("advapi32.dll")]
private static extern UInt32 RegOpenKeyEx(UInt32 hKey, string lpSubKey, UInt32 ulOptions, UInt32 samDesired, ref UInt32 phkResult);

[DllImport("advapi32.dll")]
private static extern UInt32 RegCloseKey(UInt32 hKey);

UInt32 HKEY_CLASSES_ROOT = 0x80000000;
UInt32 KEY_QUERY_VALUE = 1;
UInt32 hKey = 0;
UInt32 Result = RegOpenKeyEx(HKEY_CLASSES_ROOT, ".txt", 0, KEY_QUERY_VALUE, ref hKey);
if (Result == 0) RegCloseKey(hKey);
Console.WriteLine("Result: " + Result.ToString());