fixing my code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
My code is close to completion but I have a few issues I am not sure how to fix

<pre lang="x-cpp void enumerateapps(void) {
HGLOBAL hglbCopy;
LPTSTR lptstrCopy;
HKEY hKey;
std::wstring applist;
std::wstring outstring;
applist.clear();
LPCTSTR data_Set=L"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set, 0, KEY_READ, &hKey));
if(ret0!=ERROR_SUCCESS) {
MessageBox(NULL, L"error: cannot open the key", L"ERROR", MB_OK);
}

TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
DWORD cbName; // size of name string
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys=0; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cValues; // number of values for key
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time

DWORD i, retCode;

//TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;

// Get the class name and the value count.
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time

// Enumerate the subkeys, until RegEnumKeyEx fails.
if (cSubKeys) {
for (i=0; i<cSubKeys; i++) {
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
if (retCode == ERROR_SUCCESS) {
// _tprintf(TEXT("(%d) %sn"), i+1, achKey);
applist.push_back((TCHAR)achKey);
}
}
for (i=0; i < applist.size(); i++) {
outstring += applist;
outstring += L"/n/r";
}
OpenClipboard(NULL);
EmptyClipboard();

hglbCopy = GlobalAlloc(GMEM_MOVEABLE,(outstring.size()+1)*sizeof(TCHAR));
lptstrCopy = (LPTSTR )GlobalLock(hglbCopy);
memcpy(lptstrCopy, outstring, outstring.size()*sizeof(TCHAR));

SetClipboardData(CF_UNICODETEXT, lptstrCopy);
CloseClipboard();
}
return;
}[/code]
<br/>
<br/>


The problem is I am using std::wstring but this seems to not be too good with the current clipboard code.
Suggestions?



<
Windows MVP, http://www.windows-it.tk/services.html paid Remote Assistance is available for XP, Vista and Windows 7.
My page on http://www.hardcore-games.tk/wp/vc-overheating.html
Video Card Problems is now my most popular landing page. See my http://www.hardcore-games.tk/
gaming site for http://www.hardcore-games.tk/game-reviews.html
game reviews etc.
http://www.contract-developer.tk" target="_blank Developer |
http://www.windows-it.tk/" target="_blank Windows IT |
http://www.chessmaster.tk" target="_blank Chess | http://www.global-econ.tk" target="_blank
Economics | http://www.hardcore-games.tk/" target="_blank
Hardcore Games | http://www.vegan-advocate.tk" target="_blank
Vegan Advocate | http://www.pc-reviews.tk" target="_blank
PC Reviews
<br/>

View the full article
 
Back
Top