简体   繁体   English

ERROR_MORE_DATA — PVOID和C#—非托管类型

[英]ERROR_MORE_DATA — PVOID and C# — Unmanaged types

How can I get the value from the following DLL? 如何从以下DLL获取值? offreg.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. 在下面的代码中,我已经成功打开了配置单元,密钥,现在我试图获取密钥的值,并且继续遇到ERROR_MORE_DATA(234)错误。

Here is the C++ .dll: 这是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: 这是我的C#代码:

        [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. 因此,问题似乎与PVOID pvData有关,我似乎无法获得正确的类型或正确的缓冲区大小。 Always with the 234 error. 始终出现234错误。

NOTE: When running this command pcbdata = 28... so 256 should be more than enough. 注意:运行此命令pcbdata = 28 ...时,256应该足够了。

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... 如上所示,我尝试了字符串生成器...字符串... IntPtr ...等。这些都无法处理PVData ...

Thank you. 谢谢。

You need to initialize pcbData to the size of your buffer before passing it in. Remember C doesn't know how large of a buffer you are passing it, the pcbData value coming in tells the function how large pvData is. 您需要先将pcbData初始化为缓冲区的大小,然后再传入。记住C不知道您要传递的缓冲区有多大,传入的pcbData值告诉函数pvData的大小。 In your case you are passing in zero, telling OrGetValue that you that pvData is a 0 byte buffer, so it responds telling you it needs a larger buffer. 在您的情况下,您传入的是零,告诉OrGetValue您pvData是一个0字节的缓冲区,因此它会响应告诉您它需要更大的缓冲区。

So in your PInvoke definiation pcbData should be a ref param and have a non-zero value going in: 因此,在您的PInvoke定义中,pcbData应该是一个ref参数,并且要输入一个非零值:

[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, ref uint pcbData);

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM