Hi,
Here is a very simple example Reg Create/Write .c file (below).
When Compiled I get:
Compile by .cmd file Contents:
echo off
cls
"C:\Program Files\Tiny C\tcc.exe" "Create a Key and Write via function GOLD.c"
#define _WIN32_WINNT 0x0501 // For Win Xp.
#include <windows.h>
#include <stdio.h>
#include <winreg.h> // Adding this makes no difference in errors.
#define MAX_KEY_NAME 255
// // ~ • • • • • • • • • • • • Prototype
int KeyOpCrWrite(char *, char *);
// // ~ • • • • • • • • • • • • Prototype
// // ~ • • • • • • • • • • • • Of or pertaining to above function:
DWORD dwDisposition;
DWORD dwValue;
LONG lRes;
HKEY hkey; //..............subkey handle
HKEY hKey = HKEY_CURRENT_USER;
char cKyName;
char cVlu;
char *cKyName_prox;
char *cVlu_prox;
// // ~ • • • • • • • • • • • •
int main(int argc, char *argv[])
{
char cKyName[MAX_KEY_NAME] = "Console\\Custom1";
dwValue = 0x0000003f;
char cVlu[] = "ScreenColors";
KeyOpCrWrite(cKyName, cVlu);
// // ~ Ednt: Creating Key Here, and writing the above value to it.
printf("About to delete key\n");
system("pause");
// Then delete the subkey...
LONG res = RegDeleteKey(
hKey, // The key, followed by subkey name
cKyName_prox); //......................you can use cKyName here as I have it Also declared w Global scope.
if(res == ERROR_SUCCESS)
printf("HKEY_CURRENT_USER\\%s successfully deleted.\n", cKyName_prox);
RegCloseKey(hKey);
return 0;
}
int KeyOpCrWrite(char *cKyName_prox, char *cVlu_prox)
{
lRes = RegCreateKeyEx(hKey, // handle to an open key
cKyName_prox, // name of the subkey, Never put backslash prior to Console.
0, // Reserved, must be 0
"", // class or object type of this key, may be ignored
0, // Options
KEY_ALL_ACCESS, // Access right for the key (security
access)
NULL, // address of key security structure
&hkey, // variable that receives a handle to the opened or created key
&dwDisposition); // variable that receives result of RegCreateKeyEx one of following:
// REG_CREATED_NEW_KEY - create new key (non-exist)
// REG_OPENED_EXISTING_KEY - just open the existing key (already exist)
// If
successful
if(lRes == 0)
{
printf("The value of the \'&dwDisposition\': %u\n", dwDisposition); // Note format specifier %u !
printf("HKEY_CURRENT_USER\\%s successfully created.\n", cKyName_prox);
}
else
{
printf("value of lRes is %i\n", lRes);
printf("Creating and opening HKEY_CURRENT_USER\\%s is failed.\n", cKyName_prox);
return (1);
}
// // ~ Write value to key using RegSetValueEx
// // ~ RegSetValueEx
// Set the category message file and number of categories.
if(RegSetValueEx(hkey, // subkey handle
cVlu_prox, // value name
0, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwValue, // pointer to value data.
sizeof(DWORD))) // length of value data
{
printf("Could not set the value.");
return (1);
}
else
{
printf("The value has been set successfully.\n");
}
RegCloseKey(hKey);
return (0);
}
What am I doing wrong, not doubt something small giving me big symptoms !
Thanks,
Ed