-
August 23rd, 2013, 08:24 AM
#1
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"
-
August 23rd, 2013, 09:09 AM
#2
Re: GetPrivateProfileString Not working
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."
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 23rd, 2013, 09:20 AM
#3
Re: GetPrivateProfileString Not working
- As stated by MSFT more than 1.5 decade back
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:
Code:
inline BOOL FileExists(
const char* pszPath
);
inline BOOL FileExists(
const wchar_t* pszPath
);
//Edit: Ohh, 2kaud was faster!
Last edited by VictorN; August 23rd, 2013 at 09:24 AM.
Victor Nijegorodov
-
August 23rd, 2013, 09:56 AM
#4
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!
-
August 23rd, 2013, 10:28 AM
#5
Re: GetPrivateProfileString Not working
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.
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?
Victor Nijegorodov
-
August 23rd, 2013, 11:05 AM
#6
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?
-
August 23rd, 2013, 11:12 AM
#7
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.
Victor Nijegorodov
-
August 23rd, 2013, 11:30 AM
#8
Re: GetPrivateProfileString Not working
Originally Posted by VictorN
//Edit: Ohh, 2kaud was faster!
It's not race!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 23rd, 2013, 04:24 PM
#9
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.
-
August 24th, 2013, 04:49 AM
#10
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;
}
-
August 24th, 2013, 05:42 AM
#11
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?
-
August 24th, 2013, 06:50 AM
#12
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.
-
August 24th, 2013, 08:05 AM
#13
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
-
August 24th, 2013, 08:09 AM
#14
Re: GetPrivateProfileString Not working
Victor Nijegorodov
-
August 26th, 2013, 02:25 AM
#15
Re: GetPrivateProfileString Not working
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:
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: reading_ini_string.zip
Config.ini:
Code:
[Settings]
Value1=Test string
Test run:
Code:
J:\Temp\15>15
Value1 = Test string
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|