DWORD GetModuleFileName(
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer for module path
DWORD nSize // size of buffer, in characters hModule,让他0,就是当前的process的path了
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer for module path
DWORD nSize // size of buffer, in characters hModule,让他0,就是当前的process的path了
注意:根目录时app.path与其他情况不同!
如程序在C:\ 则app.path="C:\"
如程序在C:\01\ 则app.path="C:\01" 结尾没有"\"
or
other API(s)
Place this code in a .bas moduleOption ExplicitPublic Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As LongPublic Function GetShortName(sFile As String) As String
Dim sShortFile As String * 67
Dim lResult As Long 'Make a call to the GetShortPathName API
lResult = GetShortPathName(sFile, sShortFile, _
Len(sShortFile)) 'Trim out unused characters from the string.
GetShortName = Left$(sShortFile, lResult)End Function
'--end code block
Now place this code in the Form_Load eventPrivate Sub Form_Load() Debug.Print GetShortName(App.Path)End Sub
到底是问题简单,回答的人这么多