Teen Programmers Unite  
 

 

Return to forum top

Registry in c++

Posted by gbyte222 [send private reply] at May 20, 2003, 07:27:30 PM

I am trying to Set the value of a reg key, using this code.

char * x = "C:\\Program Files\\BUV222.exe";

RegSetValueEx(hkey, TEXT("Sys31"), 0, REG_SZ,x, 28);

But I am getting this error when I compile:
main.cpp(8) : error C2440: 'initializing' : cannot convert from 'char [28]' to 'const unsigned char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

help please

Posted by gbyte222 [send private reply] at May 20, 2003, 09:31:38 PM

Ok, I fixed that problem, but now I have another problem. I want to set the reg key to "C:\\Program Files\\BUV222.exe", but it is just not being created. It makes a folder and stuff, but it will not make the key. Tell me what I am doing wrong.

#include <windows.h>

int main()
{
HKEY hkey;
DWORD dwDisposition;
DWORD dwType, dwSize;
char * x = "C:\\Program Files\\BUV222.exe";


RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My Application"),
0, NULL, 0, 0, NULL, &hkey, &dwDisposition);
RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\My Company\\My Application"),
0, NULL, 0, 0, NULL, &hkey, &dwDisposition);
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
x = TEXT("C:\\Program Files\\BUV222.exe");
RegSetValueEx(hkey,"Sys31", 0, REG_SZ,(PBYTE) &x, sizeof(DWORD));

RegCloseKey(hkey);

return 0;
}

Posted by buzgub [send private reply] at May 21, 2003, 01:14:41 AM

check your return values. That will help you find out where it gets off the right track.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.