Skip to Content
avatar image
Former Member

Temporary filename

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

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

    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.

    Add comment
    10|10000 characters needed 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

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

    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.

    Add comment
    10|10000 characters needed characters exceeded