简体   繁体   English

ERROR_MORE_DATA-从注册表读取

[英]ERROR_MORE_DATA -— Reading from Registry

I am trying to create an offline registry in memory using the offreg.dll provided in the windows ddk 7 package. 我正在尝试使用Windows ddk 7软件包中提供的offreg.dll在内存中创建脱机注册表。

You can find out more information on the offreg.dll here: MSDN 您可以在此处找到有关offreg.dll的更多信息: MSDN

Currently, while attempting to read a value from an open registry hive / key I receive the following error: 234 or ERROR_MORE_DATA 当前,当尝试从打开的注册表配置单元/键读取值时,出现以下错误:234或ERROR_MORE_DATA

Here is the .h code that contains ORGetValue: 这是包含ORGetValue的.h代码:

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 the code that I am using to pull the data 这是我用来提取数据的代码

[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 string pvData, out uint pcbData);

        IntPtr myHive;            
        IntPtr myKey;
        string myValue;
        uint pdwtype;
        uint pcbdata;    

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

The goal is to be able to read myValue as a string. 目标是能够读取myValue作为字符串。

I am not sure if I need to use marshaling... or a second call with an adjusted buffer.. Or really how to adjust the buffer in C#. 我不确定是否需要使用封送处理或使用已调整缓冲区的第二次调用。或者实际上是如何在C#中调整缓冲区。 Any help or pointers would be greatly appreciated. 任何帮助或指针将不胜感激。

Thank you. 谢谢。

The attribute on the pcbData argument is wrong, it is ref, not out. pcbData参数上的属性是错误的,它是ref,而不是out。 You need to initialize it to the Capacity of the StringBuilder you pass for the pvData argument. 您需要将其初始化为传递给pvData参数的StringBuilder的Capacity。 Right now the API function probably sees a 0 so will return the error code. 现在,API函数可能会看到0,因此将返回错误代码。

It ought to look something like this: 它应该看起来像这样:

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

  int pdwtype;
  var buffer = new StringBuilder(256);
  int pcbdata = buffer.Capacity;
  uint ret3 = ORGetValue(myKey, "", "DefaultUserName", out pdwtype, buffer, ref pcbdata);
  string myValue = buffer.ToString();

For out string parameters you should use StringBuilder not string. 对于输出字符串参数,应使用StringBuilder而不是字符串。

The general rule is if the parameter is an LPCTSTR ( LPCSTR , LPCWSTR ) then use string, if the parameter is LPTSTR ( LPSTR , LPWSTR ) then use StringBuilder . 一般规则是,如果参数为LPCTSTRLPCSTRLPCWSTR ),则使用字符串;如果参数为LPTSTRLPSTRLPWSTR ),则使用StringBuilder

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

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