skalek
November 26th, 2005, 01:52 AM
I am having trouble getting my program to set data to a value using RegSetValueEx.
My problem definitely has to do with my lack of C knowledge and assigning the the correct data to the RegSetValueEx function..specifically the 5th argument which requires a byte (?). Can anyone steer me in the right direction?
Thanks
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
HKEY hKey;
DWORD dwType;
DWORD dwLen;
unsigned char szBuf[255] = {0};
char *homepage = "http://www.google.com";
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Main", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
return 1;
if (RegQueryValueEx(hKey, "Start Page", 0, &dwType, szBuf, &dwLen) != ERROR_SUCCESS)
return 1;
printf("Value is %s\n", szBuf);
if(RegSetValueEx(hKey,"Start Page",0,REG_SZ, (LPBYTE) homepage, sizeof(homepage) != ERROR_SUCCESS))
printf("Error in setting value\n");
else
printf("Value Set\n");
if (RegQueryValueEx(hKey, "Start Page", 0, &dwType, szBuf, &dwLen) != ERROR_SUCCESS)
return 1;
printf("Value is %s\n", szBuf);
RegCloseKey(hKey);
return 0;
}
Everything works, except for my ability to set the Start Page value to my specified home page.
My problem definitely has to do with my lack of C knowledge and assigning the the correct data to the RegSetValueEx function..specifically the 5th argument which requires a byte (?). Can anyone steer me in the right direction?
Thanks
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
HKEY hKey;
DWORD dwType;
DWORD dwLen;
unsigned char szBuf[255] = {0};
char *homepage = "http://www.google.com";
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\Main", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
return 1;
if (RegQueryValueEx(hKey, "Start Page", 0, &dwType, szBuf, &dwLen) != ERROR_SUCCESS)
return 1;
printf("Value is %s\n", szBuf);
if(RegSetValueEx(hKey,"Start Page",0,REG_SZ, (LPBYTE) homepage, sizeof(homepage) != ERROR_SUCCESS))
printf("Error in setting value\n");
else
printf("Value Set\n");
if (RegQueryValueEx(hKey, "Start Page", 0, &dwType, szBuf, &dwLen) != ERROR_SUCCESS)
return 1;
printf("Value is %s\n", szBuf);
RegCloseKey(hKey);
return 0;
}
Everything works, except for my ability to set the Start Page value to my specified home page.