Registry REG_BINARY Problem
-
im trying to get RecentDocs registry info and put it in a listctrl the name part works fine but the data part i only get the first letter
#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
HKEY hKey;
dwData = MAX_VALUE_NAME;
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i,
achValue,
&cchValue,
NULL,
&dwType,
(BYTE*)lpData,
(LPDWORD)&dwData);if (retCode == ERROR\_SUCCESS ) { m\_list.InsertItem(index, achValue); m\_list.SetItemText(index, 1, lpData); index++; }
im using vs 2008 and mfc can anyone tell me where im going wrong? :confused:
-
im trying to get RecentDocs registry info and put it in a listctrl the name part works fine but the data part i only get the first letter
#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
HKEY hKey;
dwData = MAX_VALUE_NAME;
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i,
achValue,
&cchValue,
NULL,
&dwType,
(BYTE*)lpData,
(LPDWORD)&dwData);if (retCode == ERROR\_SUCCESS ) { m\_list.InsertItem(index, achValue); m\_list.SetItemText(index, 1, lpData); index++; }
im using vs 2008 and mfc can anyone tell me where im going wrong? :confused:
-
Your attempting to pass a binary string to a function that expects a TCHAR string. You should convert it to some meaningful character string format first. The function will interpret the each byte of the binary value as char (char is a byte).
-
i forgot to add these
TCHAR lpData[MAX_VALUE_NAME];
DWORD dwType = REG_BINARY;
DWORD dwData = MAX_VALUE_NAME;but it is a TCHAR so im still lost as to what to do to fix it :(
Is yours a ANSI build (i.e. not
UNICODE
)?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Is yours a ANSI build (i.e. not
UNICODE
)?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Change:
locoone wrote:
if (retCode == ERROR_SUCCESS ) { m_list.InsertItem(index, achValue); m_list.SetItemText(index, 1, lpData); index++; }
to
if (retCode == ERROR_SUCCESS )
{
CString str = (wchar_t *) lpData;
m_list.InsertItem(index, achValue);
m_list.SetItemText(index, 1, str);
index++;
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Change:
locoone wrote:
if (retCode == ERROR_SUCCESS ) { m_list.InsertItem(index, achValue); m_list.SetItemText(index, 1, lpData); index++; }
to
if (retCode == ERROR_SUCCESS )
{
CString str = (wchar_t *) lpData;
m_list.InsertItem(index, achValue);
m_list.SetItemText(index, 1, str);
index++;
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
i changed it and i now get this error error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'ATL::CStringT<BaseType,StringTraits>'
Try (I haven't ATL here so I may only guess)
if (retCode == ERROR_SUCCESS )
{
m_list.InsertItem(index, achValue);
m_list.SetItemText(index, 1, CW2A(lpData));
index++;
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Try (I haven't ATL here so I may only guess)
if (retCode == ERROR_SUCCESS )
{
m_list.InsertItem(index, achValue);
m_list.SetItemText(index, 1, CW2A(lpData));
index++;
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]that gives the same error :(( but why am i only getting the first letter and not the whole value? :confused: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs <--- thats what im tring to get
modified on Sunday, April 12, 2009 11:07 PM
-
that gives the same error :(( but why am i only getting the first letter and not the whole value? :confused: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs <--- thats what im tring to get
modified on Sunday, April 12, 2009 11:07 PM
locoone wrote:
that gives the same error
It shouldn't.
locoone wrote:
but why am i only getting the first letter and not the whole value?
Because lpData contains a
UNICODE
string, while you need aANSI
one. Since seems you've troubles withATL
conversion macros, try using the oldie-goldieWideCharToMultyByte
[^] function. For instance (beware: quick and dirty fix):if (retCode == ERROR_SUCCESS )
{
// supposing UNICODE NOT DEFINED
char buffer[200];
WideCharToMultiByte(CP_ACP, 0, lpData, -1, buffer, 200, NULL, NULL);
m_list.InsertItem(index, achValue);
m_list.SetItemText(index, 1, buffer);
index++;
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
locoone wrote:
that gives the same error
It shouldn't.
locoone wrote:
but why am i only getting the first letter and not the whole value?
Because lpData contains a
UNICODE
string, while you need aANSI
one. Since seems you've troubles withATL
conversion macros, try using the oldie-goldieWideCharToMultyByte
[^] function. For instance (beware: quick and dirty fix):if (retCode == ERROR_SUCCESS )
{
// supposing UNICODE NOT DEFINED
char buffer[200];
WideCharToMultiByte(CP_ACP, 0, lpData, -1, buffer, 200, NULL, NULL);
m_list.InsertItem(index, achValue);
m_list.SetItemText(index, 1, buffer);
index++;
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]