CRegKey read from registry?
-
Hi, i need some help with CRegKey to read from registry :(. Here what works fine:
int *target = NULL; AfxGetApp()->GetProfileBinary(m_strKey, _T("key"), (BYTE **)&target, &bytes);
but i need to do this with registry key, like:// CRegKey is there and opened without errors int *target = NULL; myregkey.QueryBinaryValue(_T("key"), (BYTE**)&target, &bytes);
Error is allways ERROR_MORE_DATA what means they are more information to read as i do? To write binary data to registry works fine to, only read is my problem now. Only for example here how i write binary to registry:int *value = new int[count]; myregkey.SetBinaryValue(_T("key"), (BYTE*)value, sizeof(int) * count);
Can somebody help me how to read binary from registry with CRegKey::QueryBinaryValue?? Thanks in advance bosfan -
Hi, i need some help with CRegKey to read from registry :(. Here what works fine:
int *target = NULL; AfxGetApp()->GetProfileBinary(m_strKey, _T("key"), (BYTE **)&target, &bytes);
but i need to do this with registry key, like:// CRegKey is there and opened without errors int *target = NULL; myregkey.QueryBinaryValue(_T("key"), (BYTE**)&target, &bytes);
Error is allways ERROR_MORE_DATA what means they are more information to read as i do? To write binary data to registry works fine to, only read is my problem now. Only for example here how i write binary to registry:int *value = new int[count]; myregkey.SetBinaryValue(_T("key"), (BYTE*)value, sizeof(int) * count);
Can somebody help me how to read binary from registry with CRegKey::QueryBinaryValue?? Thanks in advance bosfanERROR_MORE_DATA usually means your buffer is not large enough. Call the function with a buffer that is large enough to receive the binary value.
The difficult we do right away... ...the impossible takes slightly longer.
-
Hi, i need some help with CRegKey to read from registry :(. Here what works fine:
int *target = NULL; AfxGetApp()->GetProfileBinary(m_strKey, _T("key"), (BYTE **)&target, &bytes);
but i need to do this with registry key, like:// CRegKey is there and opened without errors int *target = NULL; myregkey.QueryBinaryValue(_T("key"), (BYTE**)&target, &bytes);
Error is allways ERROR_MORE_DATA what means they are more information to read as i do? To write binary data to registry works fine to, only read is my problem now. Only for example here how i write binary to registry:int *value = new int[count]; myregkey.SetBinaryValue(_T("key"), (BYTE*)value, sizeof(int) * count);
Can somebody help me how to read binary from registry with CRegKey::QueryBinaryValue?? Thanks in advance bosfanAs per the notes for the RegQueryValueEx function[^]
Quote:
If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are undefined.
So set your variable
bytes
to zero and make the call, then when it returns it will contain the required size. You then allocate a buffer of the required size and repeat the call.Veni, vidi, abiit domum
-
As per the notes for the RegQueryValueEx function[^]
Quote:
If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData. In this case, the contents of the lpData buffer are undefined.
So set your variable
bytes
to zero and make the call, then when it returns it will contain the required size. You then allocate a buffer of the required size and repeat the call.Veni, vidi, abiit domum
Hi, thanks for Answer, you right, i solve it in this way! I didn know that i can check "the required size" :( Now:
srg.QueryBinaryValue(_T("key"), NULL, &bytes); // then if ERROR_SUCCESS int *iArr = new int[bytes]; srg.QueryBinaryValue(_T("key"), (BYTE**)&iArr[0], &bytes);
Now i now how big is the needed size, it is saved in "bytes". And i have all Data from the registry. Best regards bosfan -
ERROR_MORE_DATA usually means your buffer is not large enough. Call the function with a buffer that is large enough to receive the binary value.
The difficult we do right away... ...the impossible takes slightly longer.
-
Hi, thanks for Answer, you right, i solve it in this way! I didn know that i can check "the required size" :( Now:
srg.QueryBinaryValue(_T("key"), NULL, &bytes); // then if ERROR_SUCCESS int *iArr = new int[bytes]; srg.QueryBinaryValue(_T("key"), (BYTE**)&iArr[0], &bytes);
Now i now how big is the needed size, it is saved in "bytes". And i have all Data from the registry. Best regards bosfan -
int *iArr = new int[bytes];
Your buffer will be 4 (or even 8) times bigger than necessary; you should use:
BYTE *iArr = new BYTE[bytes];
Veni, vidi, abiit domum
You right again, i change this, but i think if i do this in this way i can call the function without cast to byte, directly? Something like this:
// regkey.QueryBinaryData(_T("key"), (BYTE**)&iArr[0], &bytes); // before regkey.QueryBinaryData(_T("key"), &iArr[0], &bytes); // now with byte array?
i try this and this works to, is there any thing wrong now? bosfan -
You right again, i change this, but i think if i do this in this way i can call the function without cast to byte, directly? Something like this:
// regkey.QueryBinaryData(_T("key"), (BYTE**)&iArr[0], &bytes); // before regkey.QueryBinaryData(_T("key"), &iArr[0], &bytes); // now with byte array?
i try this and this works to, is there any thing wrong now? bosfanI cannot find a method called
QueryBinaryData
so I presume you are referring toCRegKey::QueryBinaryValue
[^]. You could also use the simpler syntax for your buffer address thus:regkey.QueryBinaryValue(_T("key"), iArr, &bytes);
The compiler may also still insist that you cast the buffer address to a
void*
.Veni, vidi, abiit domum
-
I cannot find a method called
QueryBinaryData
so I presume you are referring toCRegKey::QueryBinaryValue
[^]. You could also use the simpler syntax for your buffer address thus:regkey.QueryBinaryValue(_T("key"), iArr, &bytes);
The compiler may also still insist that you cast the buffer address to a
void*
.Veni, vidi, abiit domum
-
Oh no, yes of course i mean QueryBinaryValue :(, my mistake :(((. One question now, is there any difference in Unicode Version, my App is in Unicode? Regards bosfan