views:

76

answers:

0

How can I get the value from the following DLL? offreg.dll.

In my below code, I have successfully opened the hive, the key and now I am trying to get the value of the key and I keep running into the ERROR_MORE_DATA (234) error.

Here is the C++ .dll:

DWORD
ORAPI
ORGetValue (
    __in ORHKEY     Handle,
    __in_opt PCWSTR lpSubKey,
    __in_opt PCWSTR lpValue,
    __out_opt PDWORD pdwType,
    __out_bcount_opt(*pcbData) PVOID pvData,
    __inout_opt PDWORD pcbData
    );

Here is my C# code:

        [DllImport("offreg.dll", CharSet = CharSet.Auto, EntryPoint = "ORGetValue", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
        public static extern uint ORGetValue(IntPtr Handle, string lpSubKey, string lpValue, out uint pdwType, out StringBuilder pvData, out uint pcbData);

            IntPtr myHive;            
            IntPtr myKey;
            StringBuilder myValue = new StringBuilder("", 256);
            uint pdwtype;
            uint pcbdata;

 uint ret3 = ORGetValue(myKey, "", "DefaultUserName", out pdwtype, out myValue, out pcbdata);

So the issue seems to be around PVOID pvData I can't seem to get the right type, or buffer size right. Always with the 234 error.

NOTE: When running this command pcbdata = 28... so 256 should be more than enough.

Any help would be greatly appreciated.

As shown above, I've tried string builder... string... IntPtr... etc. None of which were able to handle the out of PVData...

Thank you.