This topic is now archived and is closed to further replies.


Registry Fuction Questions

Recommended Posts

In a .c file I had a function to read some registry entries and make my own. It worked good and didn''t have any problems. I needed to use that code in this other project that has to be in C++ because of the wrapper class I''m using. Now that I renamed the file a .cpp file I can get any of the query and set value functions to work. I get something like this: error C2664: ''RegQueryValueExA'' : cannot convert parameter 5 from ''char *'' to ''unsigned char *'' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast And this is my code: DWORD size; RegQueryValueEx(pHKey1, "Install Path", NULL, NULL, InstallPath, &size); I get errors when I try and use RegSetValueEx(). I get pretty much the same error on the last parameter. Which is the length of the entry to be written. I was just using stren(filename) to get that. Like I said this worked great when it was just a .c file but now that its a .cpp I don''t know what the problem is.

Share this post

Link to post
Share on other sites
for some reason, your InstallPath has been declared as an unsigned char array, instead of a regular char array. Either change it back, or just use a typecast (try reinterpret_cast<char*>(InstallPath) for the fifth parameter)

How appropriate. You fight like a cow.

Share this post

Link to post
Share on other sites
you guys have it backwards ... your array is a char * right now, the function expects an unsigned char * ... in C this cast is automatic promotion I think ... in C++ it is definately not.

The SECOND parameter to the function MUST be a signed char * ... the FIFTH parameter to the function MUST be an unsigned char * ... that''s just how it works .. whenever you see the MSDN use LPCSTR, it is a signed char type ... whenever the MSDN uses a LPBYTE is is expecting an unsigned char type ...

here''s some of my code ... to help show that some things must be each type, and some things MUST be cast.

extern "C" EXPORTDLL_API HRESULT __stdcall DllRegisterServer(void)
HKEY clsidKey;
HKEY componentKey;
const char *componentID = "{6F4B8BCD-E5B6-4543-8CFF-1FC62E95D34A}";
const BYTE *componentName = (BYTE*)"Linear Number Generator";
HKEY inprocKey;
const char *inprocName = "InprocServer32";
const BYTE *systemLocation = (BYTE*)"C:\\Develop\\Install\\Component\\LinearGeneratorComponent.dll";



// create component key


// set component value - component name


// create inproc server subkey


// set inproc server value - system location



return S_OK;

Share this post

Link to post
Share on other sites
This might be a case where your target is UNICODE. Normally the APIs that have LPTSTR, or any "T*" datatype are "flexible" enough to be used by ANSI or UNICODE clients. Based on the Macro definitions UNICODE, _UNICODE the code will get compiled as UNICODE or non-UNICODE.
If you want to be generic enough, you should also use TCHAR types in your code. If you want to get away from that and want to address non-UNICODE Clients, turn off the UNICODE flags [i think they are in the project settings]. If you want to address UNICODE only clients, you can use wchar types..... [which is nothing but unsigned short*, in most of the cases.


Share this post

Link to post
Share on other sites