Sorry, I didn't think I had the PPC MSDN stuff installed here, but I do.
So, here's a really hacky function that reads a STRING key from the registry (should be easy to adapt to your needs)... tested only on W2k 'cos I don't have my PPC with me or the emulator installed:
- Code:
long getRegistryString(char **string,const char *key,const char *subkey, DWORD *dwLength)
{
long l_return;
DWORDdwType;
HKEYh_hkey;
longl_reg_return;
*string=malloc(*dwLength);
if (*string==NULL)
{
return ERROR_MEMORY_ALLOC_FAIL;
}
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,key,0,KEY_QUERY_VALUE, &h_hkey)!= ERROR_SUCCESS)
{
free(*string);
return ERROR_REGISTRY_READ_FAIL;
}
l_reg_return=RegQueryValueEx(h_hkey,subkey,NULL,&dwType,*string,dwLength);
if (l_reg_return==ERROR_MORE_DATA)
{
// attempt to redeclare entry with enough memory allocated
free(*string); // dump the existing declare
string=malloc(*dwLength);
if (string!=NULL)
{
l_reg_return=RegQueryValueEx(h_hkey,subkey,NULL,&dwType,*string,dwLength);
}
}
RegCloseKey(h_hkey);
if (*string==NULL)
{
return ERROR_MEMORY_ALLOC_FAIL;
}
if (l_reg_return!=ERROR_SUCCESS || dwType!=REG_SZ)
{
free(*string);
return ERROR_REGISTRY_READ_FAIL;
}
// We assume here that we have indeed retrieved the correct string
// the calling function takes responsibility for freeing string
return ERROR_SUCCESS;
}
Call it something like:
- Code:
DWORD dw_length=0;
char *c_filename=NULL;
l_filename_read=getRegistryString(&c_filename, TEXT("SOFTWARE\\MyCompany"), TEXT("MyData"), &dw_length);
To set the data you want the:
- Code:
LONG RegSetValueEx(
HKEY hKey,
LPCWSTR lpValueName,
DWORD Reserved,
DWORD dwType,
const BYTE *lpData,
DWORD cbData );
(Open, set, and close the key similar to the above routine).
You probably want the REG_BINARY data type, or a REG_DWORD.
Hope that helps,
Refractor