Ouvre un objet de mappage de fichier nommé
#include <WinAPIFiles.au3>
_WinAPI_OpenFileMapping ( $sName [, $iAccess = 0x0006 [, $bInherit = False]] )
$sName | Le nom de l'objet mappage de fichier à ouvrir. |
$iAccess | [optionnel] L'accès à l'objet de mappage de fichier. Ce paramètre peut prendre l'une des valeurs suivantes. $FILE_MAP_ALL_ACCESS $FILE_MAP_COPY $FILE_MAP_READ (par défaut) $FILE_MAP_WRITE (par défaut) Chacune des valeurs précédentes peuvent être combinées avec la valeur suivante: $FILE_MAP_EXECUTE |
$bInherit | [optionnel] Spécifie si le handle peut être hérité par un processus, les valeurs valides sont: True - Les processus créés par ce processus hériteront du handle. False - Les processus n'hériteront pas de ce handle (par défaut). |
Succès: | Retourne le handle de l'objet de mappage de fichier spécifié. |
Échec: | Retourne 0, appelez _WinAPI_GetLastError() pour obtenir des informations supplémentaires sur l'erreur. |
Consultez OpenFileMapping dans la librairie MSDN.
#NoTrayIcon #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <WinAPIHObj.au3> Opt('WinWaitDelay', 0) Global Const $g_sTitle = '_WinAPI_MapViewOfFile' & ChrW(160) If Not $CmdLine[0] Then If WinExists($g_sTitle) 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 = _WinAPI_OpenFileMapping('MyFileMapping') If Not $hMapping Then Return Local $pAddress = _WinAPI_MapViewOfFile($hMapping) Local $tData = DllStructCreate('wchar[1024]', $pAddress) Local $sText While WinWait($g_sTitle, '', 1) Sleep(200) $sText = DllStructGetData($tData, 1) DllStructSetData($tData, 1, '') If $sText Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_SYSTEMMODAL), $g_sTitle & " (receiver)", " " & @CRLF & $sText) WEnd _WinAPI_UnmapViewOfFile($pAddress) _WinAPI_CloseHandle($hMapping) EndFunc ;==>_Receiver Func _Sender() Local $hMapping = _WinAPI_CreateFileMapping(-1, 2048, 'MyFileMapping') If Not $hMapping Or @extended Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Erreur', 'Impossible de créer le mappage du fichier (@extended=' & @extended & ').') Return EndIf Local $pAddress = _WinAPI_MapViewOfFile($hMapping) Local $tData = DllStructCreate('wchar[1024]', $pAddress) Local $sText While WinWaitClose($g_sTitle) $sText = StringStripWS(InputBox($g_sTitle & " (sender)", 'Tapez du texte.', '', '', -1, 171), 3) If $sText = "" Then ExitLoop EndIf DllStructSetData($tData, 1, $sText) If Not WinWait($g_sTitle, '', 1) Then ExitLoop EndIf WEnd _WinAPI_UnmapViewOfFile($pAddress) _WinAPI_CloseHandle($hMapping) EndFunc ;==>_Sender