如何从 ReadProcessMemory 的输出中获取字符串
这是我的代码片段。
Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal lpBaseAddress As Long, _
lpBuffer As Any, _
ByVal nSize As Long, _
lpNumberOfBytesRead As Long) As Long
Dim bytearray As String * 65526
Dim GetWindowsFormsID
ReadProcessMemory(processHandle, bufferMem, ByVal bytearray, size, lp)
GetWindowsFormsID = ByteArrayToString(bytearray, retLength)
Function ByteArrayToString(bytes As String, length As Long) As String
Dim retValStr As String
Dim l As Long
retValStr = String$(length + 1, Chr(0))
l = WideCharToMultiByte(CP_ACP, 0, bytes, -1, retValStr, length + 1, Null, Null)
ByteArrayToString = retValStr
End Function
调用 WideCharToMultiByte 时出现“94 null”错误。 但我确信字节不为空。
这是将此输出转换为字符串的确切过程吗?
This is a snippet of my code.
Declare Function ReadProcessMemory Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal lpBaseAddress As Long, _
lpBuffer As Any, _
ByVal nSize As Long, _
lpNumberOfBytesRead As Long) As Long
Dim bytearray As String * 65526
Dim GetWindowsFormsID
ReadProcessMemory(processHandle, bufferMem, ByVal bytearray, size, lp)
GetWindowsFormsID = ByteArrayToString(bytearray, retLength)
Function ByteArrayToString(bytes As String, length As Long) As String
Dim retValStr As String
Dim l As Long
retValStr = String$(length + 1, Chr(0))
l = WideCharToMultiByte(CP_ACP, 0, bytes, -1, retValStr, length + 1, Null, Null)
ByteArrayToString = retValStr
End Function
I got '94 null' error while calling WideCharToMultiByte. But I'm sure bytes is not empty.
Is this the exact procedure to convert this output into String?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这已经解决了(还有这个问题)。 问题实际上是将 WideChar 字符串转换为 ANSI 字符串。 我使用 CopyMemory 而不是 WideCharToMultiByte。
OK, this is solved (and also this question). The issue is actually convert WideChar string into ANSI string. I use CopyMemory instead of WideCharToMultiByte.