Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CString to const unsigned *char 1

Status
Not open for further replies.

Malcav

Programmer
Oct 7, 2005
43
GB
Hi
Sorry if this has been answered before but I can find it.
I am creating a registry thing to store database connection information. I get a CString for the value. I can change the CString into a const *char but apparently it needs const unsigned *char
 
thought it might be helpfull if you saw my code :

void CreateReg (CString ConnStr)
{
const char *String ;
long result;
unsigned long result2;
unsigned long * presult2 = &result2;
HKEY keyvalue;
HKEY * pkeyval = &keyvalue;
char * subkey;

subkey = new char[15];
strcpy(subkey, "Software\\PROGRESSOR");

result = RegCreateKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, "REG_DWORD",
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, pkeyval, presult2);

if (result == ERROR_SUCCESS)
{
RegSetValueEx(keyvalue, "ConnStr", 0, REG_DWORD, String , 8);
}
}

(it is stolen from a previous registry post on here)
 
> subkey = new char[15];
> strcpy(subkey, "Software\\PROGRESSOR");
There are quite a few more than 15 characters in your string.
I don't see why you need to copy the string in the first place.

> unsigned long result2;
> unsigned long * presult2 = &result2;
There is no need to create separate variables for this.

Code:
result = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\PROGRESSOR", 0, "REG_DWORD",    
                        REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &keyval, &result2);

> const char *String ;
You don't set this to point to anything before you use it.

I imagine the CString has a method of getting at the raw data, then you can have
Code:
]
unsigned char raw[8];
memcpy( raw, connStr.something(), 8 );
RegSetValueEx(keyvalue, "ConnStr", 0, REG_DWORD, raw, 8);

--
 
as I said I ripped the code from another post about registries. the 15 was there from before.

Thanks for the help will give it a go.
 
I work I wrote into the registry. Exactly as I needed to. THank you!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top