Click to See Complete Forum and Search --> : WINDOWS REGISTRY ???


August 11th, 1999, 03:36 PM
HI,

In GetProfilestring(...) API, the first two parametrers are section name and key name can some body explain me about these two params??

Thanx

James Longstreet
August 11th, 1999, 04:06 PM
GetProfleString Will retrive from ini files unless specified. I am not sure how yuo specify with the api, but if you use the CWinApp::GetProfileString/WriteProfileString it will retrieve values from teh registry. You must call the SetRegistryKey() function to set the registry key under the default location which is
HKEY_CURRENT_USER\Software in the registry.
To use a subkey under that you can use m_pszProfileName member.
CString GetProfileString( LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL ); is the function header.
the lpszSection is the name of the section
ex: if we have a key called HKEY_CURRENT_USER\Software\Liberty Tax Service\stuff, stuff is the subkey.
the next param is lpszEntry whcih is the name of the value you wish to retrieve.
and then the last param is a default return string. ask if you still have questons


Jim Hewitt, Liberty Tax Service

August 11th, 1999, 04:31 PM
Hi,

Thanx for the answer.

I have a query.I am looking to get the path of realplay.exe which is in

HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences

How do I use CWinApp::GetProfileString(...)??

James Longstreet
August 12th, 1999, 08:16 AM
Put this function in your InitInstance of you app
SetRegistryKey((_T(HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences”));
then any calls you maek to get or write profile string should read from that protion of the registry.

Jim Hewitt, Liberty Tax Service

August 12th, 1999, 11:57 AM
HI,
HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp contains the data what I am trying to retrive.

I have SetRegKey("HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp"); in the InitInstance of my application.

and I am trying to retrive by using,

GetProfileString("HKEY_CLASSES_ROOT\\Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp", "MainApp",NULL);

Is this correct? I am unable to get the data??

prasadsunil
August 12th, 1999, 12:47 PM
I don't know what leads into this kind of discussion. Actually SetRegistryKey Always sets the key Under HKEY_CURRENT_USERS\Software . So when you say SetRegistryKey( "XXXX\\YYYY") it created entry as HKEY_CURRENT_USERS\Software\XXXX\YYYY. So you wont get any value. USe the Following code to get the Value

HRESULT UtilityFunctions::GetRegistryKeyStrVal( HKEY hKey , LPTSTR wSubkey , LPTSTR wValname,
TCHAR* lpszValue)
{

HKEY subKey;

//Open the Registry Key
if(::RegOpenKeyEx(hKey, wSubkey, 0, KEY_QUERY_VALUE,
&subKey) != ERROR_SUCCESS)
{
lpszValue = NULL;
return E_FAIL;
}

DWORD type = REG_DWORD;
DWORD cbData = 0;

// Get the Length of the Reg. key Value For allocation
if(::RegQueryValueEx(subKey, wValname, NULL,
&type, NULL, &cbData) != ERROR_SUCCESS)
{
lpszValue = NULL;
return E_FAIL;
}
//Query for Registry Value
type = REG_SZ;
TCHAR *pBuf = new TCHAR[cbData + 1];
if(::RegQueryValueEx(subKey, wValname, NULL, &type,
(LPBYTE)pBuf, &cbData) != ERROR_SUCCESS)
{
lpszValue = NULL;
return E_FAIL;
}
// Assign to the Return String
_tcscpy( lpszValue , pBuf);
//Delete the Bugger & close the Key
delete[] pBuf;
::RegCloseKey(subKey);
//return Success;
return S_OK;
}

August 12th, 1999, 06:30 PM
Thanx for the code.

Will u tell me what exactly I need to pass as "hKey","wSubkey","wValname" . I am confused with key and subkey concept!!!.

prasadsunil
August 13th, 1999, 11:01 AM
hKey is one of the Following Value
HKEY_LOCAL_MACHINE
HKEY_CURRENT_USERS
HKEY_CLASSES_ROOT etc

i your case it is HKEY_CLASSES_ROOT

wSubKey in your case is
"Software\\RealNetworks\\RealPlayer\\6.0\\Preferences\\MainApp"
wValName is NULL ( bcoz your going to retrive Default value )

Use these value and if you have any problem contact me at ssunilprasad@hotmail.com