 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Feb 07, 2008 7:23 pm Post subject: [C++ Help] SetDlgItemText + RegQueryValueEx |
|
|
Okay so i've been trying to Do Registry/INI Reading for a while.
I can write fine, but when it comes to reading using RegQueryValueEx, i cant seem to convert the string/value correctly so that SetDlgItemText can set its value/string to the edit box.
Btw it either crashes, doesnt fill the box in, fills it with the hKey (Software\\..), or just doesnt do anything. (all depending on how i arrange the strings/points/address's)
Heres my snippet, The Key is open.
(dwType, dwSize, lpwString are all defined above)
| Code: | // REG_DWORD -> Converting to wchar -> Setting to Edit Box
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
RegQueryValueEx( hKey, L"Edit Box 1", 0, &dwType, (LPBYTE)&dwValue, &dwSize );
_itot( dwValue, lpwString, 10 );
SetDlgItemText( hWnd, ID_EDIT, lpwString );
OR
// REG_SZ -> Setting straight to Edit box.
dwType = REG_SZ;
dwSize = sizeof(lpwString)+2; // For Null escape?
RegQueryValueEx( hKey, L"Edit Box 1", 0, &dwType, (LPBYTE)&lpwString, &dwSize );
SetDlgItemText( hWnd, ID_EDIT, lpwString );
RegCloseKey( hKey ); |
Wierdly enough, this one works completely fine:
| Code: | RegQueryValueEx( hKey, L"Checkbox", 0, &dwType, (PBYTE)&dwValue, &dwSize );
if ( dwValue == 1 )
{
SendDlgItemMessage( hWnd, ID_CHKBOX, BM_SETCHECK, BST_CHECKED, 0 );
}
else
{
SendDlgItemMessage( hWnd, ID_CHKBOX, BM_SETCHECK, BST_UNCHECKED, 0 );
} |
So i know for sure that it has to do with getting/converting the string, this shit has been pissing me off for a while now, so after hours and hours of googling, examples, etc. ive resorted to the forum.
Thanx to anyone who helps me.
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Feb 07, 2008 8:58 pm Post subject: |
|
|
| Code: | HKEY hKey = NULL;
LPTSTR str = "";
TCHAR strValue[255];
DWORD dwData = 0,
dwSize,
dwType = REG_SZ;
if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\diques\\coques"),
0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS){
RegQueryValueEx(hKey, TEXT("some key"), NULL, &dwType, (LPBYTE)strValue, &dwSize);
RegCloseKey(hKey);
}
str = strValue;
SetDlgItemText(hwnd, IDC_EDIT1, str); |
e: oops.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Feb 08, 2008 4:30 pm Post subject: |
|
|
Another quick example reading into a TCHAR array for the Program Files path in: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir
| Code: | #include <windows.h>
#include <iostream>
#include <tchar.h>
int main()
{
HKEY hKey = NULL;
TCHAR tszFolderPath[MAX_PATH] = {0};
DWORD dwPathSize = _ARRAYSIZE( tszFolderPath );
//
// Check If HKEY_LOCAL_MACHINE\Microsoft\CurrentVersion exists.
//
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), 0, KEY_READ, &hKey ) != ERROR_SUCCESS )
{
std::cout << "Unable to locate: SOFTWARE\\Microsoft\\Windows\\CurrentVersion" << std::endl;
std::cin.sync();
std::cin.ignore();
return 0;
}
RegCloseKey( hKey );
//
// Obtain ProgramFilesDir Key Value
//
if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), 0, KEY_READ, &hKey ) != ERROR_SUCCESS )
{
// Error
std::cout << "Unable to locate: SOFTWARE\\Microsoft\\Windows\\CurrentVersion" << std::endl;
std::cin.sync();
std::cin.ignore();
return 0;
}
else
{
if( RegQueryValueEx( hKey, _T("ProgramFilesDir"), NULL, NULL, (LPBYTE)tszFolderPath, &dwPathSize ) != ERROR_SUCCESS )
{
// Failed
std::cout << "Unable to locate: SOFTWARE\\Microsoft\\Windows\\CurrentVersion -- Key: ProgramFilesDir" << std::endl;
std::cout << tszFolderPath;
std::cin.sync();
std::cin.ignore();
return 0;
}
RegCloseKey( hKey );
}
std::cout << "Program Files Path: " << tszFolderPath;
std::cin.sync();
std::cin.ignore();
return ERROR_SUCCESS;
} |
You can alter it and then have SetDlgItemText() use tszFolderPath to set the textbox value.
_________________
- Retired. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Feb 09, 2008 11:26 am Post subject: |
|
|
Thanx guys, the TCHAR example helped alot Wiccaan!
i was thinking of using TCHAR's to, only thing that didnt work when i tried was that i wasnt using _ARRAYSIZE so that just filled in the blanks for me
everythings workin now, solved.
thanx, -Lurc
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Feb 09, 2008 8:51 pm Post subject: |
|
|
| Wiccaan wrote: | | lurc wrote: | Thanx guys, the TCHAR example helped alot Wiccaan!
i was thinking of using TCHAR's to, only thing that didnt work when i tried was that i wasnt using _ARRAYSIZE so that just filled in the blanks for me
everythings workin now, solved.
thanx, -Lurc |
Not a problem, I also noticed I forgot to close the hKey in one or two of the caes, so be sure if you error out of something that you close any open key. |
Lol dont worry, i already did that
_________________
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|