RegQueryValueEx, default value auslesen



  • Hi, ich habe im Titel genanntes versucht, auch mit der Beschreibung der MSDN, einfach einen leeren String oder NULL als Valuenamen übergeben. Jedoch klappt es nicht, er liest einfach einen leeren String aus. Was mache ich falsch?

    Gruss
    Red Storm



  • also lpData ist NULL?
    vielleicht ist der defaultwert ja einfach nicht gesetzt. schau mal in der regedit nach.



  • lpData ist 0.
    Der defaultwert ist gesetzz.

    Ich weiss immer noch nicht was ich falsch mache 😞



  • was gibt die funktion denn zurück?

    Return Values
    If the function succeeds, the return value is ERROR_SUCCESS.

    If the function fails, the return value is a nonzero error code defined in WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.



  • void CRegistrirungDlg::OnBnClickedButton1()
    {
    HKEY test;
    DWORD dwSize,dwType;
    void *pData;

    RegOpenKeyEx(HKEY_LOCAL_MACHINE, "\\SOFTWARE\\Shareaza", 0, KEY_READ, &test);

    RegQueryValueEx(test, "", NULL, &dwType, NULL, &dwSize);

    pData = malloc(dwSize);

    if(RegQueryValueEx(test, "", NULL, &dwType, (BYTE*)pData, &dwSize) == ERROR_SUCCESS)
    MessageBox("Success");
    CString b;
    b = ((char*)pData);
    MessageBox(b);

    WinExec(b, SW_SHOW);

    RegCloseKey(HKEY_LOCAL_MACHINE);

    }

    Ich finde den fhler nicht 🙄



  • ich find den fehler auch nicht aber was spricht gegen CWinApp::SetRegistryKey und CWinApp::GetProfileString. vl funktionierts so...



  • GetProfileString ist aber veraltet
    [quote=MSDN]The GetProfileString function retrieves the string associated with a key in the specified section of the Win.ini file.

    Note This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry.
    [/quote]
    Es sollte doch mit RegQueryValueEx() gehen?



  • ich hab ja auch von CWinApp::GetProfileString() und nicht von GetProfileString() geredet. ich glaub nicht, dass funktionen der MFC 16-bit sind...

    (aber, dass die MFC veraltet ist, ist ja nichtmal so falsch. wird ja auch von microsoft nicht mehr weiterentwickelt soweit ich gehört hab)



  • also CString CWinApp::GetProfileString sieht so aus:

    CWinApp::GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry,
    	LPCTSTR lpszDefault)
    {
    	ASSERT(lpszSection != NULL);
    	ASSERT(lpszEntry != NULL);
    	if (m_pszRegistryKey != NULL)
    	{
    		HKEY hSecKey = GetSectionKey(lpszSection);
    		if (hSecKey == NULL)
    			return lpszDefault;
    		CString strValue;
    		DWORD dwType, dwCount;
    		LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
    			NULL, &dwCount);
    		if (lResult == ERROR_SUCCESS)
    		{
    			ASSERT(dwType == REG_SZ);
    			lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
    				(LPBYTE)strValue.GetBuffer(dwCount/sizeof(TCHAR)), &dwCount);
    			strValue.ReleaseBuffer();
    		}
    		RegCloseKey(hSecKey);
    		if (lResult == ERROR_SUCCESS)
    		{
    			ASSERT(dwType == REG_SZ);
    			return strValue;
    		}
    		return lpszDefault;
    	}
    	else
    	{
    		ASSERT(m_pszProfileName != NULL);
    
    		if (lpszDefault == NULL)
    			lpszDefault = &afxChNil;    // don't pass in NULL
    		TCHAR szT[4096];
    		DWORD dw = ::GetPrivateProfileString(lpszSection, lpszEntry,
    			lpszDefault, szT, _countof(szT), m_pszProfileName);
    		ASSERT(dw < 4095);
    		return szT;
    	}
    }
    

    vielleicht hilft ja ein vergleich


Anmelden zum Antworten