on 01-23-2017 12:57 PM - last edited on 02-03-2024 5:12 PM by postmig_api_4
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.