Page 1 of 1

Help, preference routine strange behavior [SOLVED]

Posted: Wed Feb 07, 2007 4:40 am
by SkyManager
My PB 4.02 IDE runs the following codes with correct results.
However, when I compile it into exe, it cannot read the preference file settings.
Pls help

[code]
OpenPreferences("test.ini")
PreferenceGroup("Global")
MessageRequester("", ReadPreferenceString("OUTPUT_PATH","C:\"), #PB_MessageRequester_Ok)
MessageRequester("", ReadPreferenceString("SERVER_IP","127.0.0.1"), #PB_MessageRequester_Ok)
ClosePreferences()
[/code]

Posted: Wed Feb 07, 2007 4:56 am
by netmaestro
Is the test.ini file in the same folder with the exe?

Posted: Wed Feb 07, 2007 10:16 am
by SkyManager
Yes, test.ini is in the same folder as the generated exe

Posted: Wed Feb 07, 2007 12:14 pm
by Trond
Try to put in a PrintN(GetCurrentDirectory()) to see if the current directory isn't the same as the location of the exe.

Posted: Thu Feb 08, 2007 7:18 am
by SkyManager
My program (test.exe) and the ini file (test.ini) are stored in C:\temp
But the reported current directory is C:\

How can this happen?
Running in IDE is correct.

Posted: Thu Feb 08, 2007 7:19 am
by SkyManager
I mean how can I set the current directory to be the same as the exe running directory?

Posted: Thu Feb 08, 2007 9:41 am
by Trond
Purebasic contains a function to get the executable location. Refer to filenames relative to this location and it will work.

Posted: Fri Feb 09, 2007 1:40 am
by SkyManager
I've found it.
I also found a better solution, that is, using GetHomeDirectory()
Thank you a lot. :D