I must be missing some elemetary but I can't see it.
Here's the problem:
I have an INI file in the same directory as the exe
I want to get one of the keys in the file, but FF_INI_GetKey
is always returning the default.
The field is very simple: MySetup.INI
[Settings]
IP= MyDatabaseLocation
I am using the following to get the IP value
gIniFile = "MySetup.ini"
gIP = FF_INI_GetKey (gIniFile, "Settings", "IP", "Default")
? gIP
gIP always comes back as "Default"
Since both the EXE and the INI are in the same directory I don't have to supply a path.... Or do I ?
What am I doing wrong?
FF_INI_GetKey uses the GetPrivateProfileString API funtion.
GetPrivateProfileString requires the full path of the ini file otherwise it searches the Windows directory:
http://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx
You can get your App Path with the PB9's EXE.Path$. like this:
gIniFile = Exe.Path$ & "MySetup.ini"
Cho,
thanks.... minor details can make for problems
...Marty
Instead of PB's ExePath you also could alternatively use FireFly's App.Path.
Oh, I was looking for something like that in FF Functions Help file but somehow missed it.
Yes FF handles it exactly like VB. You will lke it.
In the past I was using the CurDir$ PB function; but in some specific cases it doesn't work well (I can't remember exactly why).
Local lIniFile As String : lIniFile = CurDir$+"\"+"MyAppsIniFile.ini"
So now I use the APP.Path from FF without any problem.
Local lIniFile As String : lIniFile = APP.Path+"\"+"MyAppsIniFile.ini"
Jean-Pierre
App.Path will return the full path up to the last backslash (\) so there is no need to concatenate the "\".
This will do:
lIniFile = APP.Path & "MyAppsIniFile.ini"
Issues with CurDir$ usually involve a shortcut that sets the working directory when running the exe. You also run into issues when the root directory is the current directory because different rules need applied for the \ in that case. If you have logic to add \ or remove \ usually you will need to check for it and make sure when done it isn't missing or doubled for all cases.