我在哪里可以找到VB6中的GetProcessImageFileName?

时间:2011-12-09 14:46:13

标签: vb6 windows-xp

我正在尝试在VB6应用程序中编写对GetProcessImageFileName的调用,但是得到了......

Run-time error '453':
    Can't find DLL entry point GetProcessImageFileName in PSAPI.DLL

我理解它可以在文档here中的PSAPI.DLL中找到。

我的代码看起来像......

Public Declare Function GetProcessImageFileName Lib "PSAPI.DLL" _
        (ByVal hProcess As Long, _
         lpImageName As String, _
         ByVal nSize As Long) As Long

Public Sub MySub()
Dim name_length As Long
Dim image_name As String
...fill in process handle...
name_length = GetProcessImageFileName(process_handle, image_name, 1024)

有谁知道我应该在这做什么? 我在Windows XP上运行。

编辑正如JosephH所建议,我已将代码更改为使用GetProcessImageFileNameA,因此......

Public Declare Function GetProcessImageFileNameA Lib "PSAPI.DLL" _
        (ByVal hProcess As Long, _
         lpImageName As String, _
         ByVal nSize As Long) As Long

name_length = GetProcessImageFileNameA(process_handle, image_name, 1024)

执行此操作(与W版本相同)会导致程序和VB6开发环境崩溃,因此在某处隐藏了另一个问题。

1 个答案:

答案 0 :(得分:4)

应该是GetProcessImageFileNameAGetProcessImageFileNameW。接受字符串作为参数的大多数Windows API函数(除了GetProcAddress)都有两个原型,一个带有ANSI(带有A后缀),另一个带有unicode(带有W后缀)

Public Declare Function GetProcessImageFileName Lib "PSAPI.DLL" Alias "GetProcessImageFileNameA" _
    (hProcess As Long, _
     ByVal lpImageName As String, _
     nSize As Long) As Long

name_length = GetProcessImageFileNameA(process_handle, image_name, 1024)