Click here to Skip to main content
15,887,302 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Class as a DLL Pin
Victor Nijegorodov24-Jan-18 9:34
Victor Nijegorodov24-Jan-18 9:34 
QuestionHow to create a thread in C Android NDK Pin
ptr_Electron22-Jan-18 3:47
ptr_Electron22-Jan-18 3:47 
QuestionRe: How to create a thread in C Android NDK Pin
Richard MacCutchan22-Jan-18 4:32
mveRichard MacCutchan22-Jan-18 4:32 
AnswerRe: How to create a thread in C Android NDK Pin
CPallini22-Jan-18 9:49
mveCPallini22-Jan-18 9:49 
QuestionRegistry returning FILE_NOT_FOUND Pin
Richard Andrew x6420-Jan-18 13:46
professionalRichard Andrew x6420-Jan-18 13:46 
AnswerRe: Registry returning FILE_NOT_FOUND Pin
Randor 20-Jan-18 16:40
professional Randor 20-Jan-18 16:40 
GeneralRe: Registry returning FILE_NOT_FOUND Pin
Richard Andrew x6421-Jan-18 2:16
professionalRichard Andrew x6421-Jan-18 2:16 
GeneralRe: Registry returning FILE_NOT_FOUND Pin
Randor 21-Jan-18 6:26
professional Randor 21-Jan-18 6:26 
Richard,

Richard Andrew x64 wrote:
I notice that you opened the HKEY without specifying a subkey in the call to RegOpenKeyEx. You only specified the subkey in the call to RegGetString. Is that the way it's supposed to work? Should I not pass a subkey to RegOpenKeyEx?


No.

Your sample code works even if I open the subkey in the call to RegOpenKeyEx.

C++
HKEY hKey;
DWORD dwResult = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, &hKey);
if (ERROR_SUCCESS == dwResult)
{
    std::wstring subkey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
    std::wstring value = L"OneDrive";
    RegGetString(hKey, subkey, value);
}
RegCloseKey(hKey);


Your original bug is due to the fact that you are sending an empty string instead of a null pointer. Make the following change:

C++
inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const std::wstring& value)
{
	//
	// Request the size of the string, in bytes
	//
	DWORD dataSize{};
	LONG retCode = ::RegGetValue(
		hKey,
		nullptr, //NULL POINTER ... NOT AN EMPTY STRING
		value.c_str(),
		RRF_RT_REG_SZ,
		nullptr,
		nullptr,
		&dataSize);
	if (retCode != ERROR_SUCCESS)
	{
		int iDebug = 0;
	}
	return L"";
}


The MSDN documentation is poorly written. You should be following the rules described in the documentation for the RegOpenKeyEx function[^] lpSubKey parameter.


The lpSubKey parameter can be NULL only if hKey is one of the predefined keys. If lpSubKey is NULL and hKey is HKEY_CLASSES_ROOT, phkResult receives a new handle to the key specified by hKey. Otherwise, phkResult receives the same hKey handle passed in to the function.


Use the 'Is this Page Helpful' button at the bottom of the MSDN documentation for the RegGetValue function[^] and report the discrepancy.

Best Wishes,
-David Delaune
GeneralRe: Registry returning FILE_NOT_FOUND Pin
Richard Andrew x6421-Jan-18 9:32
professionalRichard Andrew x6421-Jan-18 9:32 
QuestionRe: Registry returning FILE_NOT_FOUND Pin
Richard MacCutchan20-Jan-18 21:11
mveRichard MacCutchan20-Jan-18 21:11 
AnswerRe: Registry returning FILE_NOT_FOUND Pin
Victor Nijegorodov21-Jan-18 1:07
Victor Nijegorodov21-Jan-18 1:07 
QuestionScript Writing in AutoHotKey Pin
ThatOldGuy19-Jan-18 3:11
ThatOldGuy19-Jan-18 3:11 
AnswerRe: Script Writing in AutoHotKey Pin
Richard MacCutchan19-Jan-18 4:00
mveRichard MacCutchan19-Jan-18 4:00 
GeneralRe: Script Writing in AutoHotKey Pin
ThatOldGuy19-Jan-18 4:12
ThatOldGuy19-Jan-18 4:12 
GeneralRe: Script Writing in AutoHotKey Pin
Rick York19-Jan-18 5:08
mveRick York19-Jan-18 5:08 
GeneralRe: Script Writing in AutoHotKey Pin
Richard MacCutchan19-Jan-18 5:29
mveRichard MacCutchan19-Jan-18 5:29 
GeneralRe: Script Writing in AutoHotKey Pin
ThatOldGuy19-Jan-18 7:12
ThatOldGuy19-Jan-18 7:12 
GeneralRe: Script Writing in AutoHotKey Pin
Richard MacCutchan19-Jan-18 8:06
mveRichard MacCutchan19-Jan-18 8:06 
GeneralRe: Script Writing in AutoHotKey Pin
ThatOldGuy19-Jan-18 8:49
ThatOldGuy19-Jan-18 8:49 
QuestionProblem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 0:24
Member 1363226319-Jan-18 0:24 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 0:36
mveRichard MacCutchan19-Jan-18 0:36 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 0:59
Member 1363226319-Jan-18 0:59 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 1:05
mveRichard MacCutchan19-Jan-18 1:05 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 1:22
Member 1363226319-Jan-18 1:22 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 1:23
mveRichard MacCutchan19-Jan-18 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.