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
);
My code
[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);
ret3=ERROR_MORE_DATA 234
Problem can be in wrong StringBuilder Size, or FILETIME
2nd How i should call PWSTR param from C#?
[MarshalAs(UnmanagedType.LPWStr)]out StringBuilder lpName is it correct?
This is a pretty standard Windows error code, it means that you called a winapi function and you didn’t pass a big enough buffer. The only way to fix the problem is to pass a bigger buffer.
This looks a lot like a wrapper for RegQueryKeyEx(), which makes it very likely that you are passing bad data to the function. The lpcName argument is actually
ref int, not IntPtr. And you are supposed to pass a variable that stores the size of the buffer you passed, 255 in your case. The lpcClass argument is similarly borked. This ought to fix it: