كيفية الحصول على سلسلة من إخراج ReadProcessMemory

StackOverflow https://stackoverflow.com/questions/633251

  •  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

وحصلت على خطأ '94 لاغيا "بينما دعت WideCharToMultiByte. ولكن أنا على يقين بايت ليس فارغا.

هل هذا هو الإجراء الصحيح لتحويل هذا الناتج إلى سلسلة؟

هل كانت مفيدة؟

المحلول

وموافق، وهذا هو حلها (وأيضا هذا السؤال ) . المسألة هي في الواقع تحويل سلسلة WideChar إلى سلسلة ANSI. يمكنني استخدام CopyMemory بدلا من WideCharToMultiByte.

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top