1. ENRICO MENEGOTTO
  2. PowerBuilder
  3. Tuesday, 1 December 2020 16:53 PM UTC

Hi,

i'm migrating from PB 12.5 to PB 2019-R2.

In PB 12.5 to get the path of the userprofile folder, I used this syntax declaring an external global function.

FUNCTION Long GetTempPath(Long nBufferLength, REF String lpBuffer) LIBRARY "KERNEL32.DLL" ALIAS FOR "GetTempPathA;Ansi"

I have 2 questions:

1) Is in PB2019-R2 a way to have the TEMP folder with an embedded powerbuilder function?

2) How can I declare a function that works even with 32 and 64 bit environment?

Thank.

Henry.

CSTEAM.com

 

Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Wednesday, 2 December 2020 07:53 AM UTC
  2. PowerBuilder
  3. # 1

1) Is in PB2019-R2 a way to have the TEMP folder with an embedded powerbuilder function?

You can get the value of any environment variable via GetContextService.

This will get you the value of %USERPROFILE%:

string ls_values[]
ContextKeyword lcx_key
 
GetContextService ('Keyword', lcx_key)
lcx_key.GetContextKeywords ('USERPROFILE', ls_values)

GetTempPath uses the first of the following that is set: TMP, TEMP, USERPROFILE, WINDIR

So to replicate the exact behaviour of the api function, you'd have to check them in that order.

Comment
  1. mike S
  2. Wednesday, 2 December 2020 14:56 PM UTC
to expand on Benjamin's answer, use TEMP as your keyword if you want the system TEMP folder

lcx_key.GetContextKeywords ("TEMP", ls_values)



the PB documentation doesn't provide decent examples of how to use GetContextKeywords.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 1 December 2020 18:51 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Henry - 

The points Chris has listed in his response are excellent.

There is a four-part tutorial in the Articles & Blogs > Tutorials > PowerBuilder section of the Appeon Community web site titled "Interfacing PB Applications with the Windows API" you may find useful, particularly if you are going to delve into creating 64-bit PB apps.

Here's a link to the PB Tutorials:

https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder

Good luck!

John

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 1 December 2020 17:12 PM UTC
  2. PowerBuilder
  3. # 3

Hi Henry;

   Your declaration is pre-PB10.0. Since PB 10.0 and higher versions are Unicode based, I would change the declaration to ...

FUNCTION Long GetTempPath ( Long nBufferLength, REF String lpBuffer) LIBRARY "KERNEL32.DLL" ALIAS FOR "GetTempPathW"

  You should no longer have any ANSI based external MS-Windows API's in your PB App external DLL declarations. That is my personal recommendation.

   For Win32/64 compliance, the main thing to remember is any function that uses a "Handle" argument should now be use the new LongPTR data type.

Regards ... Chris

Comment
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.