本帖最后由 anilsoft 于 2015-01-09 09:57:01 编辑

解决方案 »

  1.   

    下面2个函数应该可以的吧:
    GetCurrentProcessId
    GetModuleFileName 
      

  2.   

    GetModuleFileName得到的是DLL的文件名,我需要调用DLL的程序文件全路径,DLL是自己写,程序文件不是自己写的,没参数传过来
      

  3.   

    在你的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 也是可以的
      

  4.   

    哦,该死的键盘!
    msgobx ModuleName ==>msgbox ModuleName 
      

  5.   

    谢谢,我已经找到答案了,用的
    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文件路径。