如何从注册表中读取REG_BINARY值关联值? [英] How can i read a REG_BINARY values associated value from registry?
问题描述
注册表中有一个(或多个)键,具体取决于您拥有多少个监视器 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\DEL404C\ {Some Unique ID} \\ \\Device参数\EDID
,它是一个 REG_BINARY键
。在我的情况下,这是:
00 FF FF FF FF FF FF 00 10 AC 4C 40 53 43 34 42 34 14 01 03 0A 2F 1E 78 EE EE 95 A3 54
4C 99 26 0F 50 54 A5 4B 00 71 4F 81 80 B3 00 01 01 01 01 01 01 01 01 01 21 39 90 30
62 1A 27 40 68 B0 36 00 DA 28 11 00 00 1C 00 00 00 FF 00 34 57 31 4D 44 30 43 53 42 34
43 53 0A 00 00 00 FC 00 44 45 4C 4C 20 50 32 32 31 30 0A 20 20 00 00 00 FD 00 38 4B 1E
53 10 00 0A 20 20 20 20 20 20 00 FA
此reg_binary值包含有关所连接的显示器的信息(例如序列号和类型)。我只需要这两个值。我的问题是如何使用C或C ++读取这些值?
我有一个VB脚本可以这样做:
'如果位置包含序列号如果它以& H00 00 00 ff
strSerFind = Chr(& H00) Chr(& H00)& Chr(& H00)&模型描述如果它以
& H00 00 00开头fc
strMdlFind = Chr(& H00)& Chr(& H00)& Chr(& H00)&此链接还包含有关EDID的信息: http://en.wikipedia.org/wiki/Extended_display_identification_data
有人可以帮助我,我怎么能这样做在C?我只能找到VB脚本示例,但不幸的是我不明白他们,也将对我非常重要。
解决方案
DWORD GetLocalMachineProfileBuffer(BYTE * pBuffer,DWORD nMaxLength)
{
CString szSubKey =HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\DEL404C {Some Unique ID} \Device Parameters\EDID;
DWORD rc;
DWORD dwType;
HKEY hOpenedKey;
if(ERROR_SUCCESS == RegOpenKeyEx(
HKEY_LOCAL_MACHINE,// open of open key
szSubKey,//要打开的子项名称的地址
0,//保留
KEY_READ,//安全访问掩码
& hOpenedKey //开放键的句柄地址
))
{
rc = RegQueryValueEx(
hOpenedKey,
(const char *)szValueName,
0,
& dwType,
(LPBYTE)pBuffer,
& nMaxLength);
if(rc!= ERROR_SUCCESS)
{
return(DWORD)-1;
}
else
{
ASSERT(dwType == REG_BINARY);
}
RegCloseKey(hOpenedKey);
return nMaxLength;
}
else
{
return(DWORD)-1;
}
}
这样调用:
BYTE Buffer [20000];
DWORD nLength = GetLocalMachineProfileBuffer(Buffer,sizeof(Buffer));
In the registry there is one ( or more ) key depending how many monitors you have HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\DEL404C\{Some Unique ID}\Device Parameters\EDID
which is a REG_BINARY key
. In my case this is :
00 FF FF FF FF FF FF 00 10 AC 4C 40 53 43 34 42 34 14 01 03 0A 2F 1E 78 EE EE 95 A3 54
4C 99 26 0F 50 54 A5 4B 00 71 4F 81 80 B3 00 01 01 01 01 01 01 01 01 01 01 21 39 90 30
62 1A 27 40 68 B0 36 00 DA 28 11 00 00 1C 00 00 00 FF 00 34 57 31 4D 44 30 43 53 42 34
43 53 0A 00 00 00 FC 00 44 45 4C 4C 20 50 32 32 31 30 0A 20 20 00 00 00 FD 00 38 4B 1E
53 10 00 0A 20 20 20 20 20 20 00 FA
This reg_binary value contains information (such as Serial Number and Type) about the connected monitor. I only need these two values. My question is how can i read these values using C or C++?
I have a VB script which can do this:
'you can tell If the location contains a serial number If it starts with &H00 00 00 ff
strSerFind=Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&HfF)
'or a model description If it starts with &H00 00 00 fc
strMdlFind=Chr(&H00) & Chr(&H00) & Chr(&H00) & Chr(&Hfc)
This link also contains information about EDID: http://en.wikipedia.org/wiki/Extended_display_identification_data
Could someone help me, how can i do this in C? I can find only VB script examples, but unfortunately i don't understand them, and also it would be very important for me.
解决方案 DWORD GetLocalMachineProfileBuffer(BYTE* pBuffer, DWORD nMaxLength )
{
CString szSubKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY\DEL404C{Some Unique ID}\Device Parameters\EDID";
DWORD rc;
DWORD dwType;
HKEY hOpenedKey;
if( ERROR_SUCCESS == RegOpenKeyEx (
HKEY_LOCAL_MACHINE, // handle of open key
szSubKey, // address of name of subkey to open
0, // reserved
KEY_READ, // security access mask
&hOpenedKey // address of handle of open key
) )
{
rc = RegQueryValueEx(
hOpenedKey,
(const char*)szValueName,
0,
&dwType,
(LPBYTE)pBuffer,
&nMaxLength );
if( rc != ERROR_SUCCESS )
{
return (DWORD)-1;
}
else
{
ASSERT( dwType == REG_BINARY );
}
RegCloseKey( hOpenedKey );
return nMaxLength;
}
else
{
return (DWORD)-1;
}
}
call it like this:
BYTE Buffer[20000];
DWORD nLength = GetLocalMachineProfileBuffer( Buffer, sizeof( Buffer ) );
这篇关于如何从注册表中读取REG_BINARY值关联值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!