CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 1999
    Location
    CA
    Posts
    91

    Quick/Fast/Urgent: How to get DOS path

    How do I get the ms dos path for any given path? It would be perfect if I could pass a function a string for the long path, and it would return the dos path.

    I swear I saw this before, but couldn't find it. I hope I wasn't dreaming!


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

    Re: Quick/Fast/Urgent: How to get DOS path

    there is a GetShortPathname API


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

    Re: Quick/Fast/Urgent: How to get DOS path

    here is a complete sample with a callable function:


    option Explicit
    private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (byval lpszLongPath as string, byval lpszShortPath as string, byval cchBuffer as Long) as Long
    private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" _
    (byval dwFlags as Long, lpSource as Any, _
    byval dwMessageId as Long, byval dwLanguageId as Long, _
    byval lpBuffer as string, byval nSize as Long, _
    Arguments as Long) as Long
    private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

    private Sub Command1_Click()
    MsgBox gsp("c:\programme\microsoft visual Studio")
    End Sub

    Function gsp(byval longpath as string) as string
    Dim lResult as Long
    Dim sp as string * 255
    lResult = GetShortPathName(longpath, sp, len(sp))
    If lResult > 0 then
    gsp = Left(sp, lResult)
    else
    Dim strbuffer as string * 255
    FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, byval 0, Err.LastDllError, _
    0, strbuffer, len(strbuffer), 0
    Err.Raise Number:=vbObjectError + 1001, _
    Description:=strbuffer
    End If
    End Function





  4. #4
    Join Date
    Apr 1999
    Location
    Netherlands
    Posts
    181

    Re: Quick/Fast/Urgent: How to get DOS path

    Lothar, just a little hint for your format message:
    add FORMAT_MESSAGE_IGNORE_INSERTS as constant, else VB will crash with certain errors (eg. error 129 will cause one) (error that accept inserts (%1, %2, etc, as in sprinf in C)

    Crazy D @ Work :-)

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