Skip to Content
0

Temporary filename

Jan 23, 2017 at 12:57 PM

21

avatar image
Former Member

Hi,

I am trying to get temp file name in a variable. I declared the following Global external function .

FUNCTION integer GetTempFileNameA (ref string tempdir, ref string prefix, integer seed, ref string tempfile ) LIBRARY "kernel32"

I given the following code but it returns 0 .

.

string ls_tempdir = "c:/temp"

string ls_prefixe = "xls"

integer li_seed = 0

string ls_filename

ls_filename = space(256)

li_rc = GetTempFileNameA(ls_tempdir, ls_prefixe, li_seed, ls_filename)

IF li_rc = 0 THEN

MessageBox("Invalid file name", "Error")

ELSE

MessageBox("Unique filename", ls_filename)

END IF
return ls_filename

Any help would be very appreciate

Regards

pol

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member Jan 23, 2017 at 02:04 PM
0

If you're using PB 10 or above, you need to use the W version of the function call, OR the ANSI declaration.

Either this (preferred):

FUNCTION integer GetTempFileName (ref string tempdir, ref string prefix, integer seed, ref string tempfile ) LIBRARY "kernel32" alias for "GetTempFileNameW"

or

FUNCTION integer GetTempFileName (ref string tempdir, ref string prefix, integer seed, ref string tempfile ) LIBRARY "kernel32" alias for "GetTempFileNameA;ANSI"

By declaring the function name without the A or W, you can change the Alias portion without needing to change all of your code.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi brad

I had done the same way you advised but still the code is not working

FUNCTION integer GetTempFileName (ref string tempdir, ref string prefix, integer seed, ref string tempfile ) LIBRARY "kernel32" alias for "GetTempFileNameW"

integer li_rc

string ls_tempdir = "c:\temp\"

string ls_prefixe = "app"

integer li_seed = 0

string ls_filename

ls_filename = space(256)

li_rc = GetTempFileName(ls_tempdir, ls_prefixe, li_seed, ls_filename)

IF li_rc = 0 THEN

MessageBox("Oups", "Error")

ELSE

MessageBox("Unique filename", ls_filename)

END IF
return ls_filename

Any Help would be very appreciate

0
avatar image
Former Member Jan 24, 2017 at 02:38 PM
0

I tested the function declaration and found I had missed a couple things.

This works (tested):

FUNCTION long GetTempFileName (string tempdir, string prefix, long seed, ref string tempfile ) LIBRARY "kernel32" alias for "GetTempFileNameW"

If something in the Windows API says "UINT", it should be considered a LONG to powerbuilder. References to strings don't need to be used unless it's being modified.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Many Thanks. Now working

0