Click to See Complete Forum and Search --> : ExpandEnvironmentStrings


Wgilster
October 8th, 1999, 01:43 PM
The call is simple enough but everthing that I have done, and what other people have showed me doesn't seem to work. Everytime I get an empty string from this. What is wrong?


private Declare Function ExpandEnvironmentStrings Lib "kernel32" Alias "ExpandEnvironmentStringsA" (byval lpSrc as string, byval lpDst as string, byval nSize as Long) as Long

private Sub Command1_Click()
Dim sString as string
sString = Space(255)
Call ExpandEnvironmentStrings("Path = %PATH%", byval sString, 255)
sString = Left(sString, InStr(sString, Chr(0)) - 1)
Text1 = sString
End Sub

Lothar Haensler
October 11th, 1999, 01:55 AM
I tried your code, and yes, it did NOT work.
Why?
- the buffer was too small. In Nt my path was longer than 255 bytes.
- thus, make your buffer bigger.

Better yet, trap the return code from ExpandEn... and pass it to FormatMessage API to get the human-readable explanation of the failure.