|
-
Aug 6th, 2000, 12:45 PM
#1
Thread Starter
Lively Member
Does somebody knows how I can get the DOS path of my app? When I use App.Path I get the path with long names but for example I would like "C:\Program Files\..." like this: 'C:\PROGRA~1\...'.
Help me please, I need fast help!!!
-
Aug 6th, 2000, 12:52 PM
#2
Monday Morning Lunatic
MSDN says:
Code:
DWORD GetShortPathName(
LPCTSTR lpszLongPath, // null-terminated path string
LPTSTR lpszShortPath, // short form buffer
DWORD cchBuffer // size of short form buffer
);
so that translates to:
Code:
Declare Function GetShortPathName Alias GetShortPathNameA Lib "kernel32" (lpszLongPath as String, lpszShortPath as String, cchBuffer as Long)
The remarks are:
Parameters
lpszLongPath
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path.
Windows NT/2000: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98: This string must not exceed MAX_PATH characters.
lpszShortPath
[out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath.
cchBuffer
[in] Specifies the size, in TCHARs, of the buffer pointed to by lpszShortPath.
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.
If the function fails due to the lpszShortPath buffer being too small to contain the short path string, the return value is the size, in TCHARs, of the short path string, including a terminating null. In this event, call the function again with a short path buffer that is at least as large as the return value times the size of a TCHAR.
If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.
Remarks
When an application calls this function and specifies a path on a volume that does not support 8.3 aliases, the function fails with ERROR_INVALID_PARAMETER if the path is longer than 67 bytes.
The path specified by lpszLongPath does not have to be a full or a long path. The short form may be longer than the specifed path.
If the specified path is already in its short form, there is no need for any conversion, and the function simply copies the specified path to the buffer for the short path.
You can set lpszShortPath to the same value as lpszLongPath; in other words, you can set the buffer for the short path to the address of the input path string.
You can obtain the long name of a file from the short name by calling the GetLongPathName function. Alternatively, where GetLongPathName is not available, you can call FindFirstFile on each component of the path to get the corresponding long name.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 6th, 2000, 01:11 PM
#3
Thread Starter
Lively Member
When I use this code I get an error and 'alias' is marked. I get the message 'Compile error: expected: Lib'.
Maybe this code is wrong???
Can somebody also give me an example code??
Thanx
-
Aug 6th, 2000, 01:14 PM
#4
Monday Morning Lunatic
Sorry...
Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (lpszLongPath As String, lpszShortPath As String, cchBuffer As Long) As Long
[Edited by parksie on 08-06-2000 at 02:17 PM]
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 6th, 2000, 02:08 PM
#5
Thread Starter
Lively Member
Example...
Thanx for the replies
but...
Can somebody please say me (or give the example code) how I can (with this function) get from the app.path the short path as caption of Label1?
-
Aug 6th, 2000, 03:05 PM
#6
Monday Morning Lunatic
Shove this into your form:
Code:
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Function GetShortFilename(ByVal sLongFilename As String) As String
'Returns the Short Filename associated with sLongFilename
Dim lRet As Long
Dim sShortFilename As String
'First attempt using 1024 character buffer.
sShortFilename = String$(1024, " ")
lRet = GetShortPathName(sLongFilename, sShortFilename, Len(sShortFilename))
'If buffer is too small lRet contains buffer size needed.
If lRet > Len(sShortFilename) Then
'Increase buffer size...
sShortFilename = String$(lRet + 1, " ")
'and try again.
lRet = GetShortPathName(sLongFilename, sShortFilename, Len(sShortFilename))
End If
'lRet contains the number of characters returned.
If lRet > 0 Then
GetShortFilename = Left$(sShortFilename, lRet)
End If
End Function
Private Sub Form_Load()
Label1.Caption = GetShortFilename(App.Path)
End Sub
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|