2009-03-11 5 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 null '오류가 발생했습니다. 그러나 바이트가 비어 있지 않은 것은 확실합니다.

alt text

이 문자열에이 출력을 변환 할 수있는 정확한 절차인가?

답변

1

정상,이 문제는 해결되었습니다 (또한 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 
관련 문제