映射文件映射视图到调用进程的地址空间.
#Include <WinAPIEx.au3>
_WinAPI_MapViewOfFile ( $hMapping [, $iOffset [, $iBytes [, $iAccess]]] )
$hMapping | 文件映射对象的句柄. 由 _WinAPI_CreateFileMapping() 和 _WinAPI_OpenFileMapping() 函数返回此句柄. |
$iOffset | [可选参数] 视图开始的文件偏移量. |
$iBytes | [可选参数] 将映射到视图的文件映射的字节数 所有字节都必须是 _WinAPI_CreateFileMapping() 指定的最大大小. 如果 $iBytes 为 0, 映射从指定的偏移量延伸到文件映射结束. |
$iAccess | [可选参数] 文件映射的访问类型. 可以是以下值之一: $FILE_MAP_ALL_ACCESS --- 映射文件的读/写视图 $FILE_MAP_COPY --- 映射文件的写入复制视图 $FILE_MAP_READ --- 映射文件的只读视图 $FILE_MAP_WRITE --- 映射文件的读/写视图 每个值的前面可以组合下面值: $FILE_MAP_EXECUTE --- 映射可执行文件的视图(映射内存可以运行的代码) |
成功: | 返回映射视图的起始地址. |
失败: | 返回 0,设置 the @error 为非 0 值. |
在MSDN中搜索
#NoTrayIcon
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Opt('WinWaitDelay', 0)
Global Const $Title = '_WinAPI_MapViewOfFile' & ChrW(160)
If Not $CmdLine[0] Then
If WinExists($Title) Then
Exit
EndIf
For $i = 1 To 2
If Not @compiled Then
Run(@AutoItExe & ' "' & @ScriptFullPath & '" /' & $i)
Else
Run(@AutoItExe & ' /' & $i)
EndIf
Sleep(500)
Next
Exit
EndIf
Opt('TrayIconHide', 0)
Switch $CmdLine[1]
Case '/1'
_Sender()
Case '/2'
_Receiver()
Case Else
Exit
EndSwitch
Func _Receiver()
Local $hMapping, $pAddress, $tData, $Text
$hMapping = _WinAPI_OpenFileMapping('MyFileMapping')
If @error Then
Return
EndIf
$pAddress = _WinAPI_MapViewOfFile($hMapping)
$tData = DllStructCreate('wchar[1024]', $pAddress)
While WinWait($Title, '', 1)
Sleep(200)
$Text = DllStructGetData($tData, 1)
DllStructSetData($tData, 1, '')
If $Text Then
MsgBox(64, $Title, $Text)
EndIf
WEnd
_WinAPI_UnmapViewOfFile($pAddress)
_WinAPI_CloseHandle($hMapping)
EndFunc ;==>_Receiver
Func _Sender()
Local $hMapping, $pAddress, $tData, $Text
$hMapping = _WinAPI_CreateFileMapping(-1, 2048, 'MyFileMapping')
If (@error) Or (@extended) Then
MsgBox(16, 'Error', 'Unable to create file mapping.')
Return
EndIf
$pAddress = _WinAPI_MapViewOfFile($hMapping)
$tData = DllStructCreate('wchar[1024]', $pAddress)
While WinWaitClose($Title)
$Text = StringStripWS(InputBox($Title, 'Type some text message.', '', '', -1, 171), 3)
If Not $Text Then
ExitLoop
EndIf
DllStructSetData($tData, 1, $Text)
If Not WinWait($Title, '', 1) Then
ExitLoop
EndIf
WEnd
_WinAPI_UnmapViewOfFile($pAddress)
_WinAPI_CloseHandle($hMapping)
EndFunc ;==>_Sender