CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Location
    Iowa, USA
    Posts
    3

    ExpandEnvironmentStrings

    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






  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: ExpandEnvironmentStrings

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured