Help, preference routine strange behavior [SOLVED]

Windows specific forum
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Help, preference routine strange behavior [SOLVED]

Post 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]
Last edited by SkyManager on Sun Mar 04, 2007 3:57 am, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Is the test.ini file in the same folder with the exe?
BERESHEIT
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

Yes, test.ini is in the same folder as the generated exe
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post 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.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

I mean how can I set the current directory to be the same as the exe running directory?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Purebasic contains a function to get the executable location. Refer to filenames relative to this location and it will work.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post by SkyManager »

I've found it.
I also found a better solution, that is, using GetHomeDirectory()
Thank you a lot. :D
Post Reply