| | | | Public Declare Function rpiVirtualWrite Lib "rpiAccessProcess.DLL" ( _ ByVal dwThreadID As Long, _ ByVal lpSourceAddress As Long, _ ByVal lpTargetAddress As Long, _ ByVal dwSize As Long) As Long | | | | | | This function first checks to make sure that the edge identified by dwThreadID and lpAddress actually emanates from the calling thread's node, since we cannot allow a strange thread to write to memory allocated by another thread! (In a sense, writing memory is like pushing data along the edge, and it better be the correct edge.) | | | | | | The rpiVirtualWrite function then calls the API function WriteProcessMemory, discussed in Chapter 16, Windows Messages. To do so, it calls GetWindowThreadProcessId, to get the process ID from the target dialog handle, and then it calls OpenHandle to get a process handle, which is required by WriteProcessMemory. | | | | | | The rpiVirtualRead Function | | | | | | The rpiVirtualRead function is: | | | | | | int WINAPI rpiVirtualRead( DWORD dwThreadID, LPVOID lpSourceAddress LPVOID lpTargetAddress, DWORD nSize ); | | | | | | Public Declare Function rpiVirtualRead Lib "rpiAccessProcess.DLL" ( _ ByVal dwThreadID As Long, _ ByVal lpSourceAddress As Long, _ ByVal lpTargetAddress As Long, _ ByVal dwSize As Long) As Long | | | | | | As with the rpiVirtualWrite function, this function first checks that the edge emanates from the calling thread's node. (In a sense, reading is like pulling data along the edge backwards.) It then calls the API function ReadProcessMemory. | | | | Example: Foreign Control Extraction | | | | | | We have seen that it is not difficult to extract data from a foreign listbox or combo box, because Windows automatically marshalls the necessary data across process boundaries. However, the same does not apply to the 32-bit controls such as the ListView control. In this case, we must do the marshalling ourselves. | | | | | | To get the rpiControlExtractor application, first discussed in Chapter 16, to work on a ListView control, we can use the rpiAccessProcess allocation function to allocate a | | |