本帖最后由 gyp2000 于 2021-3-19 07:24 编辑
不知道你的发送端是如何写的代码,只能给你发个例子了。。
接收端#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
#include <APISysConstants.au3>
#include <AutoItConstants.au3>
Global $hGUI,$COPYDATA
Global Const $iWM_COPYDATA = _WM_COPYDATA_Start()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $iWM_COPYDATA
$vDummyValue = _WM_COPYDATA_GetData()
;ToolTip($vDummyValue)
ConsoleWrite($vDummyValue&@CRLF)
$vDummyValue = 0
Case Else
EndSwitch
WEnd
Func _WM_COPYDATA_GetData()
Local $sReturn = $COPYDATA
$COPYDATA = ''
Return $sReturn
EndFunc
Func _WM_COPYDATA_Start()
Local $idDummy
$hGUI = GUICreate('{6C90F37A-228E-3787-A733-342BCD36CAFB}', 0, 0, -99, -99, '', $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $hGUI)
If IsAdmin() Then
_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_COPYDATA, $MSGFLT_ALLOW)
EndIf
GUIRegisterMsg($WM_COPYDATA, '_WM_COPYDATA')
$idDummy = GUICtrlCreateDummy()
Return $idDummy
EndFunc
Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local Const $tagCOPYDATASTRUCT = 'ptr;dword;ptr' ; 'ulong_ptr;dword;ptr'
Local Const $tParam = DllStructCreate($tagCOPYDATASTRUCT, $lParam)
Local Const $tData = DllStructCreate('wchar[' & DllStructGetData($tParam, 2) + 1 & ']', DllStructGetData($tParam, 3)) ; wchar
$COPYDATA = StringLeft(DllStructGetData($tData, 1), DllStructGetData($tParam, 2))
GUICtrlSendToDummy($iWM_COPYDATA)
EndFunc
发送端#include <WindowsConstants.au3>
#include <SendMessage.au3>
$hWnd = WinGetHandle('{6C90F37A-228E-3787-A733-342BCD36CAFB}')
For $s =1 To 10
_COPYDATA_Send($hWnd, "这是一个COPYDATA消息")
Next
Func _COPYDATA_Send($hWnd, $sMsg)
Local Const $tBuffer = DllStructCreate('wchar cdata[' & StringLen($sMsg) + 1 & ']')
DllStructSetData($tBuffer, 'cdata', $sMsg)
Local Const $tagCOPYDATASTRUCT = 'ptr dwData;dword cbData;ptr lpData' ; 'ulong_ptr dwData;dword cbData;ptr lpData'
Local Const $tCOPYDATASTRUCT = DllStructCreate($tagCOPYDATASTRUCT)
DllStructSetData($tCOPYDATASTRUCT, 'dwData', 0)
DllStructSetData($tCOPYDATASTRUCT, 'cbData', DllStructGetSize($tBuffer))
DllStructSetData($tCOPYDATASTRUCT, 'lpData', DllStructGetPtr($tBuffer))
_SendMessage($hWnd, $WM_COPYDATA, 0, DllStructGetPtr($tCOPYDATASTRUCT))
Return Number(Not @error)
EndFunc
|