
Untitled
By: a guest on
Jul 15th, 2012 | syntax:
None | size: 1.91 KB | hits: 17 | expires: Never
DllImport ERROR_MORE_DATA UNMANAGED Call C in C#
DWORD OREnumKey(
__in ORHKEY Handle,
__in DWORD dwIndex,
__out PWSTR lpName,
__inout PDWORD lpcName,
__out_opt PWSTR lpClass,
__inout_opt PDWORD lpcClass,
__out_opt PFILETIME lpftLastWriteTime
);
[DllImport("offreg.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint OREnumKey(IntPtr Handle, IntPtr dwIndex, [MarshalAs(UnmanagedType.LPWStr)]out StringBuilder lpName, ref IntPtr lpcName, [MarshalAs(UnmanagedType.LPWStr)]out StringBuilder lpClass, ref IntPtr lpcClass, out System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime);
IntPtr myKey = hiveid;
IntPtr dwindex=(IntPtr)0;
StringBuilder lpName=new StringBuilder("",255);
IntPtr lpcName = (IntPtr)0;
StringBuilder lpClass=new StringBuilder("",255);
IntPtr lpcClass = (IntPtr)11;
System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime;
uint ret3 = OREnumKey(myKey, dwindex, out lpName, ref lpcName, out lpClass, ref lpcClass, out lpftLastWriteTime);
[DllImport("offreg.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint OREnumKey(
IntPtr Handle,
int dwIndex,
StringBuilder lpName,
ref int lpcName,
StringBuilder lpClass,
ref int lpcClass,
out System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime);
...
StringBuilder lpName=new StringBuilder("",255);
int nameSize = lpName.Capacity;
StringBuilder lpClass=new StringBuilder("",255);
int classSize = lpClass.Capacity;
System.Runtime.InteropServices.ComTypes.FILETIME lpftLastWriteTime;
uint ret3 = OREnumKey(hiveid, 0, lpName, ref nameSize, lpClass, ref classSize, out lpftLastWriteTime);
if (ret3 != 0) throw new Exception("kaboom");
string name = lpName.ToString();
string className = lpClass.ToString();