Const $FILE_MAP_READ = 4
Const $FILE_MAP_WRITE = 2
Const $SECTION_NAME = "jzt_output_price"
Local $hSection = OpenFileMapping(BitOR($FILE_MAP_READ, $FILE_MAP_WRITE), 0, $SECTION_NAME)
Local $pBaseAddress = MapViewOfFile($hSection, BitOR($FILE_MAP_READ, $FILE_MAP_WRITE), 0, 0, 0)
; Do something with the $pBaseAddress
UnmapViewOfFile($pBaseAddress)
CloseHandle($hSection)
Func OpenFileMapping($iDesiredAccess, $fInheritHandle, $sSectionName)
Local $iResult
$iResult = DllCall("Kernel32.dll", "handle", "OpenFileMappingW", "dword", $iDesiredAccess, "bool", $fInheritHandle, "wstr", $sSectionName)
Return $iResult[0]
EndFunc ;==>OpenFileMapping
Func MapViewOfFile($hSection, $iDesiredAccess, $iOffsetHigh, $iOffsetLow, $iNumberofBytesToMap)
Local $iResult
$iResult = DllCall("Kernel32.dll", "ptr", "MapViewOfFile", "handle", $hSection, "dword", $iDesiredAccess, "long", $iOffsetHigh, "long", $iOffsetLow, "long", $iNumberofBytesToMap)
Return $iResult[0]
EndFunc ;==>MapViewOfFile
Func CloseHandle($hObject)
Local $iResult
$iResult = DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hObject)
Return $iResult[0]
EndFunc ;==>CloseHandle
Func UnmapViewOfFile($pBaseAddress)
Local $iResult
$iResult = DllCall("Kernel32.dll", "bool", "UnmapViewOfFile", "ptr", $pBaseAddress)
Return $iResult[0]
EndFunc ;==>UnmapViewOfFile
进程通信必须要满足两个原则,一是能够数据共享,二是必须有线程同步机制。用内存映射的方式来回传递数据并不算真正意义上的进程通信,因为它只有数据共享,而没有线程同步,所以就必须在一个循环中实时监测内存中的数据。 |