GetPrivateProfileString Not working
I am trying to use ini file for configuring my app.
But GetPrivateProfileString is not working.
I am using Windows 7. I tried "Wow64DisableWow64FsRedirection" also.
Not only this-ATLPath::FileExists is also not working.It gives an error code 0x80070002 which means:
"system could not find the file"
Re: GetPrivateProfileString Not working
Quote:
But GetPrivateProfileString is not working.
How is it not working? How are you using it? It would be helpful if you posted the code in which it is used.
Note that according to Microsoft, "GetPrivateProfileString is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry."
Re: GetPrivateProfileString Not working
- As stated by MSFT more than 1.5 decade back
Quote:
This function is provided only for compatibility with 16-bit versions of Windows. Win32-based applications should store initialization information in the registry.
Why don't you want to use registry? - What exactly "is not working"? What does it return? Did you read the MDN documentation about it?
- WHat ATLPath::FileExists do you mean and how do you use it? MSDN shows the following signature for it:
Quote:
Code:
inline BOOL FileExists(
const char* pszPath
);
inline BOOL FileExists(
const wchar_t* pszPath
);
//Edit: Ohh, 2kaud was faster! ;)
Re: GetPrivateProfileString Not working
OK, Now I wrote code for writing to registry. But what if in the target machine user doesn't have enough previlages?
I hope usually all users will have access to HKEY_LOCAL_MACHINE\SOFTWARE. Is it OK?
ATLPath::FileExists() returns FALSE even though I gave an existing path as paramater. Why?
I think the problem is that platform is 64 bit. Please try the code in windows 7 and tell me whether it works!
Re: GetPrivateProfileString Not working
Quote:
Originally Posted by
shjdr7
OK, Now I wrote code for writing to registry. But what if in the target machine user doesn't have enough previlages?
I hope usually all users will have access to HKEY_LOCAL_MACHINE\SOFTWARE. Is it OK?
It is OK as long as user reads the registry. User cannot write in HKEY_LOCAL_MACHINE.
Quote:
Originally Posted by
shjdr7
ATLPath::FileExists() returns FALSE even though I gave an existing path as paramater. Why?
I think the problem is that platform is 64 bit. Please try the code in windows 7 and tell me whether it works!
Where is your code?
Re: GetPrivateProfileString Not working
I will give the code later. If user cannot write to registry how he will configure the application? Which registry key I should use?
Re: GetPrivateProfileString Not working
User usually saves application settings in HKCU (HKEY_CURENT_USER\Software\<Company name>\<application name>)
In HKEY_LOCAL_MACHINE you could save some initial data/settings (while installing your app!) that are common to all the users supposed to use your app. And those data/settings will never been changed.
Re: GetPrivateProfileString Not working
Quote:
Originally Posted by
VictorN
//Edit: Ohh, 2kaud was faster! ;)
It's not race!:D
Re: GetPrivateProfileString Not working
I have some programs that use it. It works. You'll need to post code and be more specific about what's not working.
Re: GetPrivateProfileString Not working
//Try this code in windows 7 with 64 bit
TCHAR strFileName[MAX_PATH] = {0};
::GetModuleFileName(ModuleHelper::GetModuleInstance(),strFileName,MAX_PATH);
ATLPath::RemoveFileSpec(strFileName);
ATLPath::Append(strFileName,_T("Config.INI"));
ATLTRACE(strFileName);//File exists I tested the trace output
ATLTRACE(_T("\n"));
if(!ATLPath::FileExists(strFileName))
{
HRESULT hr = ATL::AtlHresultFromLastError();
ATLTRACE("%x\n",hr);//system could not find the file specified!
return;
}
Re: GetPrivateProfileString Not working
I've tested your code and it works fine (Windows 7, 64-bit).
Are you sure you have double-checked the existence and the path of that file?
Re: GetPrivateProfileString Not working
Anyway, placing that .INI file in the application's folder is not a good idea.
Instead, put it under a special folder dedicated for that purpose (would be Application Data), then call SHGetKnownFolderPath or the older SHGetFolderPath.
For a list of special folders, have a look in MSDN Library: http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx.
Re: GetPrivateProfileString Not working
Anyway I am using registry now. I hope using HKEY_CURENT_USER will be safe - User in target machine will have privilages to write in the registry
Re: GetPrivateProfileString Not working
1 Attachment(s)
Re: GetPrivateProfileString Not working
Quote:
Originally Posted by
shjdr7
I am trying to use ini file for configuring my app.
But GetPrivateProfileString is not working.
I am using Windows 7. I tried "Wow64DisableWow64FsRedirection" also.
Not only this-ATLPath::FileExists is also not working.It gives an error code 0x80070002 which means:
"system could not find the file"
The most frequent beginner's mistake is to not provide a fully specified path to .ini file.
From MSDN:
Quote:
lpFileName [in]
The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.
Sample: Attachment 31731
Config.ini:
Code:
[Settings]
Value1=Test string
Test run:
Code:
J:\Temp\15>15
Value1 = Test string