Thanks guys for all the help. (BYTE *)m_license_key.GetBuffer(0) worked best for me =) Really appreciate it.
trumper
Posts
-
Insert value from GUI CString into Registry -
Insert value from GUI CString into RegistryHi, So I have this code to open a handle hKey which works fine. RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\MyProgram", 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); Then I try to set a value from a GUI CString member variable m_license_key into registry. RegSetValueEx(hKey, "PROGRAM_KEY", 0L, REG_DWORD,(LPBYTE)&m_license_key, sizeof(DWORD)); The set function also works fine other than the fact that "rubbish" gets inserted as value for my registry key. In other words, HKEY_LOCAL_MACHINE\\SOFTWARE\\MyProgram\\PROGRAM_KEY is added, but the value is not what I keyed into m_license_key (it is just some strange text or some 0xHex numbers) To be honest, I do not know what to specify for parameters 4, 5, 6 of RegSetValueEx. Any help would be greatly appreciated. Thanks.
-
"synchronized" method call in dllHi David, I took your advice and things seem fine now. No more global variables in the header file for me anymore :laugh: Thanks
-
"synchronized" method call in dllHi David, Thanks for the reply. I have tried using static and got the same result. I am quite sure only one instance of the dll is being loaded each time my test application is using it as I have other code in DllMain that clears the UI of all user input (which I don't see happening). Thanks
-
"synchronized" method call in dllHi, I am trying to write a "synchronized" function call in my dll so that programmers that use my api can expect to only make single-instance function calls. The basic motivation is that each function call spawns a thread hence I would like to greatly restrict the number of threads spawned (basically 1-and-only-1 thread spawn per function call to my api). //In my program.h header file int threadCode = 0; //no problem if threadCode is instantiated in the header file HANDLE threadMutexEvent; #define PROC_THREAD 0 #define ERR_THREAD_INUSE 1 //In my program.cpp program file BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { //problem arises if I instantiate threadCode here //threadCode = 0; threadMutexEvent = CreateEvent(NULL, false, true, "MutexEvent"); return true; } int WINAPI processRequest() { WaitForSingleObject(threadMutexEvent, INFINITE); if(threadCode == PROC_THREAD) { threadCode = ERR_THREAD_INUSE; SetEvent(threadMutexEvent); } else { SetEvent(threadMutexEvent); return ERR_THREAD_INUSE; } //spawn thread to do some work for me return 0; } As you can see, I am using Win32's synchronization mechanism to do some simple synchronization on the global variable threadCode. As seen in the code comments listed above, everything is fine if I instantiate threadCode in the header file, however, once I shift the instantiation of threadCode to DllMain the synchronization gets messed up. Basically, seperate function calls to processRequest would always "see" threadCode == PROC_THREAD and go ahead to spawn another thread (which is what I am trying to prevent :() If all things fail I would fall back on leaving the instantiation in the header file, but I am really curious as to why the 2 seemingly identical instantiation calls would result in 2 drastically different results. Thanks