Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

temporary windows folder name?

759 views
Skip to first unread message

Somnath

unread,
May 12, 2009, 8:55:20 AM5/12/09
to
Hi,

I am trying to get the temporary windows folder name. I declared local
external function as follows:
FUNCTION ulong GetTempPathA (long nBufferLength, ref string lpBuffer )
LIBRARY "KERNEL32.DLL"

Then have the following code in the clicked event of a button on the window:
constant long lcl_maxpath = 260
string ls_tempdir
ulong lul_retval
ls_tempdir = Fill('0', lcl_maxpath)
lul_retval = parent.GetTempPatha(lcl_maxpath, ls_tempdir)
IF lul_retval > 0 THEN
Messagebox("Temp path", ls_tempdir)
END IF

The above code displays chinese letters only instead of the path name!

I am using Windows Vista Business and PowerBuilder 11.5

Does anybody know the solution to this problem? Am I calling the right
function?

TIA,

Somnath

Krzysztof Korolonek

unread,
May 12, 2009, 9:16:33 AM5/12/09
to
Hi!
We use this:

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

and then:

String ls_temppath

ls_temppath = Space(255)
GetTempPath(255,ls_temppath)

It's working in PB 11.5 under Windows Vista Business

Best regards!
Krzysztof Korolonek

Dave Hauze

unread,
May 12, 2009, 9:20:02 AM5/12/09
to
Yes, but there is a Unicode version of the function (GetTempPathW), though
either solution would work, since PB 10+ is natively Unicode, I would think
using the unicode function would be the best option since it is available,
instead of telling PB to for this instance, use ANSI.

--
Dave Hauze
"Krzysztof Korolonek" <krzysztof...@fibermedia.pl> wrote in message
news:4a0976b1@forums-1-dub...

Dave Hauze

unread,
May 12, 2009, 9:17:56 AM5/12/09
to
I'm guessing you're using PB 10.0 or greater, which is now Unicode and you
are using an ANSI function.

Use the unicode version of the function "GetTempPathW(long nBufferLength,
ref string lpBuffer)"

Or you can add the Alias statement after the function declaration, like:

GetTempPathW(long nBufferLength, ref string lpBuffer) ALIAS FOR
"GetTempPathA;ANSI"

--
Dave Hauze
"Somnath" <junka...@somedomain.com> wrote in message
news:4a0971b8@forums-1-dub...

Roland Smith [TeamSybase]

unread,
May 12, 2009, 12:30:47 PM5/12/09
to
When you use "funcnameA;Ansi", PowerBuilder converts all strings from
Unicode to Ansi and calls the A version of the function. Within the function
itself, it converts all strings from Ansi to Unicode and then calls the W
version. So it would be more efficient to just call the W version directly.

"Dave Hauze" <david...@steeldynamics.com> wrote in message
news:4a097782$1@forums-1-dub...

T. Nomura

unread,
May 12, 2009, 9:20:43 PM5/12/09
to
Hi Somnath,

You don't have to use an external function.
Instead you can use GetContextService function to get the
environment variable.

Try this.
------------------------------------------------------
ContextKeyword lcxk_base
String ls_values[]

GetContextService("ContextKeyword", lcxk_base)
lcxk_base.GetContextKeywords("TEMP", ls_values)
MessageBox("TEMP", "TEMP is : " + ls_values[1])
------------------------------------------------------

Somnath

unread,
May 13, 2009, 9:07:49 AM5/13/09
to
Thanks a lot for the clarification!

"Krzysztof Korolonek" <krzysztof...@fibermedia.pl> wrote in message
news:4a0976b1@forums-1-dub...

Dave Hauze

unread,
May 13, 2009, 9:12:56 AM5/13/09
to
That's what I was getting at... Less work to do when you use the unicode
function.

--
Dave Hauze
"Roland Smith [TeamSybase]" <rsmith_at_trusthss_dot_com> wrote in message
news:4a09a437$1@forums-1-dub...

Bob Zagars

unread,
May 28, 2009, 3:28:04 PM5/28/09
to
On May 13, 9:12 am, "Dave Hauze" <david.ha...@steeldynamics.com>
wrote:

> That's what I was getting at... Less work to do when you use the unicode
> function.
>
> --
> Dave Hauze
> "Roland Smith [TeamSybase]" <rsmith_at_trusthss_dot_com> wrote in messagenews:4a09a437$1@forums-1-dub...

>
>
>
> > When you use "funcnameA;Ansi", PowerBuilder converts all strings from
> > Unicode to Ansi and calls the A version of the function. Within the
> > function itself, it converts all strings from Ansi to Unicode and then
> > calls the W version. So it would be more efficient to just call the W
> > version directly.
>
> > "Dave Hauze" <david.ha...@steeldynamics.com> wrote in message

> >news:4a097782$1@forums-1-dub...
> >> Yes, but there is a Unicode version of the function (GetTempPathW),
> >> though either solution would work, since PB 10+ is natively Unicode, I
> >> would think using the unicode function would be the best option since it
> >> is available, instead of telling PB to for this instance, use ANSI.
>
> >> --
> >> Dave Hauze
> >> "Krzysztof Korolonek" <krzysztof.korolo...@fibermedia.pl> wrote in
> >> messagenews:4a0976b1@forums-1-dub...
> >>>> Somnath- Hide quoted text -
>
> - Show quoted text -

I used both methods but get short names anyone know how I can get long
names?

Best Regards,

Bob

Bruce Armstrong

unread,
May 28, 2009, 4:09:56 PM5/28/09
to

The GetLongPathName function in the Windows API will convert the short
name to a long name

Function Long GetLongPathName(String lpShortPath, REF String
lpLongPath, Long cBuffer) Library "kernel32.dll" ALIAS FOR
"GetLongPathNameW"

-----------------------------------

My Web 2.0 Stuff

Blog: http://bruce.pbdjmagazine.com/
Facebook: http://www.facebook.com/people/Bruce-Armstrong/1600223798
Fotki: http://public.fotki.com/brucearmstrong/
LinkedIn: http://www.linkedin.com/in/bruceaarmstrong
Twitter: http://twitter.com/bruce_armstrong
YouTube: http://www.youtube.com/user/brucearmstrong

0 new messages