Hello all, I got some problem with these functions: RegCreateKey, RegSetValueEx,RegQueryValueEx,RegOpenKeyEx and I dont need a URL to msdn. The problem is that its working 2/3 :-).
Output in the register should be like this:
Name: Test
Type: REG_SZ
Data: C:\WINDOWS\system32\test.exe

But I get this:
Name: Test
Type: REG_SZ
Data: [][][][][][][][][][][][][][]

My code is below, do anyone see the problem?
hope you dont mind to help me :-).
//KaZu



#include <windows.h>
#include <stdio.h>
#include <winuser.h>

#define BUFSIZE 120
int test_key(void);
int create_key(char *);
int main(void)
{
char *path = new char[40];
path ="C:\\WINDOWS\\system32\\test.exe";

int test,create; // just holders to get the return value from functions

test=test_key(); /*check if key is available for opening*/

if (test==2)/*create key*/
{
//*the path in which the file needs to be*/
create=create_key(path);
}


int test_key(void) // function to check if we could open the register and check the value for specified name
{
int check;
HKEY hKey;
char path[BUFSIZE];
DWORD buf_length=BUFSIZE;
int reg_key;

reg_key=RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEX("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),0,KEY_QUERY_VALUE,&hKey); // Open register
if(reg_key!=ERROR_SUCCESS)// If the value isnt ERROR_SUCCESS it have failed and returns a error, set the check = 1
{
check=1;
return check;
}

reg_key=RegQueryValueEx(hKey,TEXT("test"),NULL,NULL,(LPBYTE)path,&buf_length); // Get value for"test"

if((reg_key!=0)||(buf_length>BUFSIZE))
check=2;

if(reg_key==0)
check=0;

RegCloseKey(hKey); // Just close the key
return check;
}


int create_key(char *path)
{
int reg_key,check;
HKEY hkey;

reg_key=RegCreateKey(HKEY_LOCAL_MACHINE,TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),&hkey); // Create a key
if(reg_key==0)
{
RegSetValueEx((HKEY)hkey,TEXT("test"),0,REG_SZ,((LPBYTE)path),(sizeof(path))+1); // Set the value
check=0;
return check;
}
if(reg_key!=0)
check=1;

RegCloseKey(hkey); // close the key
return check;
}