|
-
February 13th, 2013, 02:30 AM
#5
Re: Problem with binary Registry I/O
 Originally Posted by Mike Pliam
I confess that the syntax is confusing to me. But after fooling with it for awhile, bearing in mind Igor's remarks, I came up with this that works:
Code:
unsigned char * pbkey;
//AfxGetApp()->GetProfileBinary(_T("settings"), _T("keyb"), (LPBYTE*)m_key, (UINT*)&m_nKeySize);
AfxGetApp()->GetProfileBinary(_T("settings"), _T("keyb"), &pbkey, (UINT*)&m_nKeySize);
for(int i = 0; i < m_nKeySize; i++) { TRACE1("%0.2x ", pbkey[i]); m_key[i] = pbkey[i]; } TRACE0("\n");
delete [] pbkey; pbkey = NULL;
Please note that m_key is a declared member variable (CMyDlg::m_cKey - unsigned char m_key[32]), I am unclear as to where the memory for the byte pointer pbkey is allocated and whether or not it needs to be deallocated.
Considering the way how it is to be deleted, allocation occurs in GetProfileBinary by means of new [], allocation is on-heap byte array of m_nKeySize bytes, and the array address is assigned to pbkey pointer.
Also notable is that I cannot seem to use m_key in place of pbkey,
Of course you cannot, as the method semantic implies that allocation occurs inside GetProfileBinary, and you are not allowed to provide your own buffer for receiving the binary key value.
or I have not figured out how to make that work (which would be simpler than dealing another pointer variable, pbkey), since in my particular instance, the length of the Registry binary will ALWAYS BE 32.
This is what you know, but Windows registry never knows that, and it always must be ready to ingest data of any size.
Looking at your code I cannot figure out what's wrong with storing your key as REG_SZ? Why binary?
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|