回复 2# yeqing880
;===============================================================================
;
; Description: Register Reciver Function
; Parameter(s): $sFunction - Optional, Function name to Register.
; Omit to Disable/Unregister
; Requirement(s): 3.2.4.9
; Return Value(s): On Success - Returns True
; On Failure - Returns False and Set
; @error to: 1 - Unable to create Reciver Window
; 2 - Unable to (Un)Register WM_COPYDATA or WM_USER+0x64
; Author(s): Florian 'Piccaso' Fida
; Note(s): If the process doesent have a Window it will be created
; The Reciver Function must accept 1 Parameter
;
;===============================================================================
Func _CoProcReciver($sFunction = Default)
Local $sHandlerFuction = "__CoProcReciverHandler", $hWnd, $aTmp
If IsKeyword($sFunction) Then $sFunction = ""
$hWnd = _ProcessGetWinList(@AutoItPID, "", 16 + 2)
If Not IsHWnd($hWnd) Then
$hWnd = GUICreate("CoProcEventReciver")
If @error Then Return SetError(1, 0, False)
EndIf
If $sFunction = "" Or IsKeyword($sFunction) Then $sHandlerFuction = ""
If Not GUIRegisterMsg(0x4A, $sHandlerFuction) Then Return SetError(2, 0, False) ; WM_COPYDATA
If Not GUIRegisterMsg(0x400 + 0x64, $sHandlerFuction) Then Return SetError(2, 0, False) ; WM_USER+0x64
$gs_CoProcReciverFunction = $sFunction
Return True
EndFunc ;==>_CoProcReciver
Func __CoProcReciverHandler($hWnd, $iMsg, $WParam, $LParam)
If $iMsg = 0x4A Then ; WM_COPYDATA
Local $COPYDATA, $MyData
$COPYDATA = DllStructCreate("ptr;dword;ptr", $LParam)
$MyData = DllStructCreate("char[" & DllStructGetData($COPYDATA, 2) & "]", DllStructGetData($COPYDATA, 3))
$gv_CoProcReviverParameter = DllStructGetData($MyData, 1)
Return 256
ElseIf $iMsg = 0x400 + 0x64 Then ; WM_USER+0x64
If $gv_CoProcReviverParameter Then
Call($gs_CoProcReciverFunction, $gv_CoProcReviverParameter)
If @error And @Compiled = 0 Then MsgBox(16, "CoProc Error", "Unable to Call: " & $gs_CoProcReciverFunction)
$gv_CoProcReviverParameter = 0
Return 0
EndIf
EndIf
EndFunc ;==>__CoProcReciverHandler
;===============================================================================
;
; Description: Send a Message to a CoProcess
; Parameter(s): $vProcess - Name or PID of Process
; $vParameter - Parameter to pass
; $iTimeout - Optional, Defaults to 500 (msec)
; $fAbortIfHung - Optional, Default is True
; Requirement(s): 3.2.4.9
; Return Value(s): On Success - Returns True
; On Failure - Returns False and Set
; @error to: 1 - Process not found
; 2 - Window not found
; 3 - Timeout/Busy/Hung
; 4 - PostMessage Falied
; Author(s): Florian 'Piccaso' Fida
; Note(s):
;
;==========================================================================
Func _CoProcSend($vProcess, $vParameter, $iTimeout = 500, $fAbortIfHung = True)
Local $iPid, $hWndTarget, $MyData, $aTmp, $COPYDATA, $iFuFlags
$iPid = ProcessExists($vProcess)
If Not $iPid Then Return SetError(1, 0, False) ; Process not Found
$hWndTarget = _ProcessGetWinList($vProcess, "", 16 + 2)
If @error Or (Not $hWndTarget) Then Return SetError(2, 0, False) ; Window not found
$MyData = DllStructCreate("char[" & StringLen($vParameter) + 1 & "]")
$COPYDATA = DllStructCreate("ptr;dword;ptr")
DllStructSetData($MyData, 1, $vParameter)
DllStructSetData($COPYDATA, 1, 1)
DllStructSetData($COPYDATA, 2, DllStructGetSize($MyData))
DllStructSetData($COPYDATA, 3, DllStructGetPtr($MyData))
If $fAbortIfHung Then
$iFuFlags = 0x2 ; SMTO_ABORTIFHUNG
Else
$iFuFlags = 0x0 ; SMTO_NORMAL
EndIf
$aTmp = DllCall("user32.dll", "int", "SendMessageTimeout", "hwnd", $hWndTarget, "int", 0x4A _; WM_COPYDATA
, "int", 0, "ptr", DllStructGetPtr($COPYDATA), "int", $iFuFlags, "int", $iTimeout, "long_ptr", 0)
If @error Then Return SetError(3, 0, False) ; SendMessageTimeout Failed
If Not $aTmp[0] Then Return SetError(3, 0, False) ; SendMessageTimeout Failed
$aTmp = DllCall("user32.dll", "int", "PostMessage", "hwnd", $hWndTarget, "int", 0x400 + 0x64, "int", 0, "int", 0)
If @error Then Return SetError(4, 0, False)
If Not $aTmp[0] Then Return SetError(4, 0, False)
Return True
EndFunc ;==>_CoProcSend
看了一下CoProc.au3里面的代码,也是用WM_COPYDATA这个东东,如果楼主遇到这个问题,那应该是WM_COPYDATA的问题。 |