cancel
Showing results for 
Search instead for 
Did you mean: 

Temporary filename

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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.

Former Member
0 Kudos

Many Thanks. Now working

Former Member
0 Kudos

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.

Former Member
0 Kudos

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