MFC SetRegistryKey ... Is there a GetRegistryKey function?

I have these two lines of code.

CString strHost = AfxGetApp()->GetProfileString(_T("WebServices"), _T("Server"));
AfxMessageBox(strHost);

      

Nowhere in the application do I set a value. (the installer does this). Thus, strHost should be the same no matter where and when this line is run.

Here's what I have. Press A -> run function containing code -> view expected data; Press B -> execute some windows callbacks -> run the function containing the code -> see "";

I would have thought something in B cleared the value, but if I press B first and then A, A yeilds then I don't want "."

Unfortunately, I don't have access to the code that contains the Windows callbacks, or rather, it's the largest pile of poorly managed obfiscation I've ever seen.

What am I run-of-the-mill if GetProfileString is pulling data from somewhere it shouldn't? This is the only thing I can think of.

Questions.
1.) Is there a way to confirm that I am still working with the same "key"?
2.) Has anyone ever encountered this before?

Please, if you think this is a bad question and would like to flag it as such, please leave a comment so I can fix it.


While I didn't find the complete answer, I did track down something interesting.
I am using AfxGetApp () -> GetProfileString ..
The AfxGetApp () function seems to return different things at different times. I don't know how this could have happened, but at least now I can explain it,

+1


source to share


2 answers


GetProfileString () can also read from a .ini file besides the registry. If the GetProfileString () call is made on a different CWinApp-based object than the main application (such as a dll), it might try to read from the application's .ini file. Try going to GetProfileString () to see what's going on.



However, my advcie: don't use GetProfileString (). Use CRegKey to query the registry directly. This is probably not what you want to hear, because it is important to pass the registry key. I usually #define the global APPLICATION_REG_KEY macro in stdafx.h. This is frustrating for purists, but very convenient.

+1


source


I found the answer .. Sorting. AfxGetApp function returns different objects depending on where it is called. If it calls into a DLL, for example, it returns a pointer to it. I think it even returns the wrong thing when the application uses OS calls. This means GetProfileString is for a different "profile".



I haven't found anyone who has encountered this, but I believe the problem has been resolved. Feel free to add more "answers" if you don't.

0


source







All Articles