Powerbuilder – Application path

Posted on Tuesday, April 19th, 2011 at 8:20 pm in

So you need to check some file you have deployed with your application and you have chosen to put it in the same folder as the executable. Sure, I’ll just check the current folder when the application launches and I’ll have what I need. Wrong. Since an application can be launched with a ‘Start In’ folder this is not always the correct place. Instead use the GetModuleFileName API call

First the external function declaration:

FUNCTION int GetModuleFileNameW(&
           ulong hinstModule, &
           REF string lpszPath, &
           ulong cchPath) LIBRARY "kernel32"
// or for those of you way back in time

FUNCTION int GetModuleFileNameA(&
           ulong hinstModule, &
           REF string lpszPath, &
           ulong cchPath) LIBRARY "kernel32"

Now in your script do the following:

string ls_Path
unsignedlong lul_handle

ls_Path = space(1024)

lul_handle = Handle(GetApplication())
GetModuleFilenameW(lul_handle, ls_Path, 1024)// or GetModuleFilenameA if appropriate

You can use the PFC fileservice to easily strip off the exe name from ls_path or do it yourself.

Add your comment

Leave a Reply

Top