2009-03-11 35 views
2

これは私のコードのスニペットです。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ヌル 'エラーが発生しました。しかし、私はバイトが空ではないと確信しています。

alt text

これは文字列の中に、この出力を変換するために正確な手順ですか?

答えて

1

OKこれが解決されました(またthis question)。この問題は実際に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 
関連する問題