1. ATK Gimmy Susan
  2. PowerBuilder
  3. Wednesday, 20 May 2020 12:07 PM UTC

Good morning.

I'm calling an API to get the execution path of my application (see code below).

Unfortunately, the result is not desired.

Ideas?

 

Ecosystem: Window10 64b + PB2019r2 + run in IDE

 

 

// code

Messaegbox('', go_prg.get_executionpath())

 

 

 

 

 

 

//Api

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

//[Powerscript]
string ls_Path
unsignedlong lul_handle

ls_Path = space(1024)

lul_handle = Handle(GetApplication())
GetModuleFilenameA(lul_handle, ls_Path, 1024)
return ls_Path

 

Olan Knight Accepted Answer Pending Moderation
  1. Wednesday, 20 May 2020 16:26 PM UTC
  2. PowerBuilder
  3. # 1

 

OR you can use the version of the API call you have, with just a few adjustments:

FUNCTION int GetModuleFileNameA(ulong hinstModule, REF string lpszPath, ulong cchPath) LIBRARY "kernel32" alias for "GetModuleFileNameA;Ansi"

 

Later -

Olan

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 20 May 2020 13:37 PM UTC
  2. PowerBuilder
  3. # 2

Arnd is correct on both points. From the PB Help topic "Handle (PowerScript function):

When you ask for the handle of the application, Handle returns 0 when you are using the PowerBuilder Run command. As far as Windows is concerned, your application does not have a handle when it is run from PowerBuilder. When you build and run an executable version of your application, the Handle function returns a valid handle for the application.

You should not use the ANSI flavor of any Windows API call (where the function name ends with a capital "A") unless you have a specific requirement for ANSI encoding, because PowerBuilder uses Unicode (and has since version 10). Use the Windows API function name that ends in "W" (for "wide" characters, i.e., Unicode). Please note that only the WinAPI functions that accept and/or return string/character information are made available in Unicode/ANSI versions by Windows.

Comment
There are no comments made yet.
ATK Gimmy Susan Accepted Answer Pending Moderation
  1. Wednesday, 20 May 2020 13:01 PM UTC
  2. PowerBuilder
  3. # 3

Bad news

[cit]  afaik, running from the PB IDE the Application Handle is allways 0.

 

 

this means i can't test it in debug mode

 

=(

Comment
There are no comments made yet.
Arnd Schmidt Accepted Answer Pending Moderation
  1. Wednesday, 20 May 2020 12:48 PM UTC
  2. PowerBuilder
  3. # 4

You shoud use the UniCode Version of the external Function

and afaik, running from the PB IDE the Application Handle is allways 0.

http://codeverge.com/sybase.powerbuilder.general/handle-getapplication-always-retu/1030716

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

hth

Arnd

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 20 May 2020 18:52 PM UTC
Hi Arndt;

Proper "External Function" declaration should be ....



FUNCTION uLong GetModuleFileName ( uLong lhModule, ref string sFileName, Integer inSize ) LIBRARY "KERNEL32.dll" ALIAS FOR "GetModuleFileNameW"



Also ... FYI: http://chrispollach.blogspot.com/2020/05/techtip.html



HTH Regards ... Chris
  1. Helpful
  1. Arnd Schmidt
  2. Wednesday, 20 May 2020 21:50 PM UTC
Hi Chris,

how about

FUNCTION uLong GetModuleFileName ( uLong lhModule, ref string sFileName, ulong inSize ) LIBRARY "KERNEL32.dll" ALIAS FOR "GetModuleFileNameW" ?



https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamew



















  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 20 May 2020 22:40 PM UTC
Hi Arndt;

Yes, the last parm can be either but technically your definition is better. PB just places the INT value in the lower bits of the Double Word. So the end result is the same for the size (length).

Regards ... Chris
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.