C# 使用PInvoke注册表函数,如何从句柄指针获取数据?
假设我正在使用RegQueryValueEx:C# 使用PInvoke注册表函数,如何从句柄指针获取数据?,c#,.net,pinvoke,C#,.net,Pinvoke,假设我正在使用RegQueryValueEx: 我可以得到lpType的指针句柄,但它只是一个整数,我如何才能真正得到lpType所指向的数据呢 它只是一个整数。。。它只是一个从0到7的枚举,其中0是REG_NONE。。。7是REG_MULTI_SZ。查看“键类型”下的“查找”。它只是一个整数。。。它只是一个从0到7的枚举,其中0是REG_NONE。。。7是REG_MULTI_SZ。查看键类型下的查找。
我可以得到lpType的指针句柄,但它只是一个整数,我如何才能真正得到lpType所指向的数据呢 它只是一个整数。。。它只是一个从0到7的枚举,其中0是REG_NONE。。。7是REG_MULTI_SZ。查看“键类型”下的“查找”。它只是一个整数。。。它只是一个从0到7的枚举,其中0是REG_NONE。。。7是REG_MULTI_SZ。查看键类型下的查找。
lpType
实际上应该是无符号整数类型。我决定为自己的理智做一个枚举:
/// <summary>Specify the data type to retrieve from the registry</summary>
/// <remarks> https://msdn.microsoft.com/en-us/library/windows/desktop/ms724884%28v=vs.85%29.aspx </remarks>
public enum RegDataType
{
/// <summary>[0] No defined value type.</summary>
REG_NONE,
/// <summary>[1] Null-terminated string.
/// It will be a Unicode or ANSI string, depending on whether you use the Unicode or ANSI functions.</summary>
REG_SZ,
/// <summary>[2] Null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%").
/// It will be a Unicode or ANSI string, depending on whether you use the Unicode or ANSI functions.</summary>
REG_EXPAND_SZ,
/// <summary>[3] Binary data in any form.</summary>
REG_BINARY,
/// <summary>[4] 32-bit number.</summary>
REG_DWORD,
/* /// <summary> [4] 32-bit number in little-Endean format. This is equivalent to REG_DWORD.
/// In little-Endean format, a multi-byte value is stored in memory from the lowest byte (the "little end") to the highest byte.
//// For example, the value 0x12345678 is stored as (0x78 0x56 0x34 0x12) in little-Endean format.</summary>
*/ //REG_DWORD_LITTLE_ENDIAN 4
/// <summary>[5] 32-bit number in big-Endean format.
/// In big-Endean format, a multi-byte value is stored in memory from the highest byte (the "big end") to the lowest byte.
/// For example, the value 0x12345678 is stored as (0x12 0x34 0x56 0x78) in big-Endean format.</summary>
REG_DWORD_BIG_ENDIAN,
/// <summary>[6]Unicode symbolic link.</summary>
REG_LINK,
/// <summary>[7] Array of null-terminated strings that are terminated by two null characters.</summary>
REG_MULTI_SZ,
/// <summary>[8]Device-driver resource list.</summary>
REG_RESOURCE_LIST,
/// <summary>[9] </summary>
REG_FULL_RESOURCE_DESCRIPTOR,
/// <summary>[10] </summary>
REG_RESOURCE_REQUIREMENTS_LIST,
/// <summary>[11] 64-bit number.</summary>
REG_QWORD
/* /// <summary>[11] A 64-bit number in little-Endean format. This is equivalent to REG_QWORD.</summary>
*/ //REG_QWORD_LITTLE_ENDIAN 11
}
logicnp是正确的
m0s的想法是正确的,但我会争论MSDN链接的清晰性lpType
实际上应该是无符号整数类型。我决定为自己的理智做一个枚举:
/// <summary>Specify the data type to retrieve from the registry</summary>
/// <remarks> https://msdn.microsoft.com/en-us/library/windows/desktop/ms724884%28v=vs.85%29.aspx </remarks>
public enum RegDataType
{
/// <summary>[0] No defined value type.</summary>
REG_NONE,
/// <summary>[1] Null-terminated string.
/// It will be a Unicode or ANSI string, depending on whether you use the Unicode or ANSI functions.</summary>
REG_SZ,
/// <summary>[2] Null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%").
/// It will be a Unicode or ANSI string, depending on whether you use the Unicode or ANSI functions.</summary>
REG_EXPAND_SZ,
/// <summary>[3] Binary data in any form.</summary>
REG_BINARY,
/// <summary>[4] 32-bit number.</summary>
REG_DWORD,
/* /// <summary> [4] 32-bit number in little-Endean format. This is equivalent to REG_DWORD.
/// In little-Endean format, a multi-byte value is stored in memory from the lowest byte (the "little end") to the highest byte.
//// For example, the value 0x12345678 is stored as (0x78 0x56 0x34 0x12) in little-Endean format.</summary>
*/ //REG_DWORD_LITTLE_ENDIAN 4
/// <summary>[5] 32-bit number in big-Endean format.
/// In big-Endean format, a multi-byte value is stored in memory from the highest byte (the "big end") to the lowest byte.
/// For example, the value 0x12345678 is stored as (0x12 0x34 0x56 0x78) in big-Endean format.</summary>
REG_DWORD_BIG_ENDIAN,
/// <summary>[6]Unicode symbolic link.</summary>
REG_LINK,
/// <summary>[7] Array of null-terminated strings that are terminated by two null characters.</summary>
REG_MULTI_SZ,
/// <summary>[8]Device-driver resource list.</summary>
REG_RESOURCE_LIST,
/// <summary>[9] </summary>
REG_FULL_RESOURCE_DESCRIPTOR,
/// <summary>[10] </summary>
REG_RESOURCE_REQUIREMENTS_LIST,
/// <summary>[11] 64-bit number.</summary>
REG_QWORD
/* /// <summary>[11] A 64-bit number in little-Endean format. This is equivalent to REG_QWORD.</summary>
*/ //REG_QWORD_LITTLE_ENDIAN 11
}