ReadProcessMemoryの出力から文字列を取得する方法
-
08-07-2019 - |
質問
これは私のコードのスニペットです。
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 'エラーが発生しました。しかし、バイトは空ではないと確信しています。
これは、この出力を文字列に変換する正確な手順ですか?
解決
OK、これは解決しました(およびこの質問) 。問題は、実際にWideChar文字列をANSI文字列に変換することです。 WideCharToMultiByteの代わりにCopyMemoryを使用します。
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Function ByteArrayToString(bytes As String, Length As Long) As String
Dim retValStr As String
retValStr = String(Length - 1, Chr$(0))
CopyMemory ByVal StrPtr(retValStr), ByVal bytes, Length * 2
ByteArrayToString = retValStr
End Function
所属していません StackOverflow