在你的dll里加个窗体,用下面的代码测试(这个代码是api viewer里的示例): 'Example Name:ModuleFilename Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer Const GWW_HINSTANCE = (-6) Private Sub Form_Load() 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Dim ModuleName As String, FileName As String, hInst As Long 'create a buffer ModuleName = String$(128, Chr$(0)) 'get the hInstance application: hInst = GetWindowWord(Me.hwnd, GWW_HINSTANCE) 'get the ModuleFileName: 'enter the following two lines as one, single line: ModuleName = Left$(ModuleName, GetModuleFileName(hInst, ModuleName, Len(ModuleName))) 'set graphics mode to persistent 'Me.AutoRedraw = True 'show the module filename msgobx ModuleName End Sub用GetModuleFileName+getcurrentproceeid+openprocess 也是可以的
哦,该死的键盘! msgobx ModuleName ==>msgbox ModuleName
谢谢,我已经找到答案了,用的 Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long 用 Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long 始终得到的是DLL文件路径。
GetCurrentProcessId
GetModuleFileName
'Example Name:ModuleFilename
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
Const GWW_HINSTANCE = (-6)
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim ModuleName As String, FileName As String, hInst As Long
'create a buffer
ModuleName = String$(128, Chr$(0))
'get the hInstance application:
hInst = GetWindowWord(Me.hwnd, GWW_HINSTANCE)
'get the ModuleFileName:
'enter the following two lines as one, single line:
ModuleName = Left$(ModuleName, GetModuleFileName(hInst, ModuleName, Len(ModuleName)))
'set graphics mode to persistent
'Me.AutoRedraw = True
'show the module filename
msgobx ModuleName
End Sub用GetModuleFileName+getcurrentproceeid+openprocess 也是可以的
msgobx ModuleName ==>msgbox ModuleName
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
用
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
始终得到的是DLL文件路径。