Jump to content



Photo

[SOLVED] WM_COPYDATA & x64 Issue


  • Please log in to reply
3 replies to this topic

#1 guinness

guinness

    guinness

  • MVPs
  • 10,273 posts

Posted 10 September 2010 - 09:08 AM

I tidied the code from a post made by KaFu. The code is fully working in both x32 & x64. I also used _CmdLineRaw() to parse $CmdLineRaw to an Array.

Function: Version 7 (31/12/2012) (Save as WM_COPYDATA.au3)
AutoIt         
#cs     Thanks to the following for helping in the past ...     KaFu for the idea from _EnforceSingleInstance().     Yashied for x64 support. #ce #include <WinAPI.au3> #include <WindowsConstants.au3> Global Enum $__hInterCommunicationGUI, $__iInterCommunicationControlID, $__sInterCommunicationIDString, $__sInterCommunicationData, $__iInterCommunicationMax Global $__vInterCommunicationAPI[$__iInterCommunicationMax] ; Internal array for the WM_COPYDATA functions. Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)     #forceref $hWnd, $iMsg, $wParam     Local Const $tagCOPYDATASTRUCT = 'ulong_ptr;dword;ptr'     Local $tParam = DllStructCreate($tagCOPYDATASTRUCT, $lParam)     Local $tData = DllStructCreate('wchar[' & DllStructGetData($tParam, 2) / 2 & ']', DllStructGetData($tParam, 3))     $__vInterCommunicationAPI[$__sInterCommunicationData] = DllStructGetData($tData, 1)     GUICtrlSendToDummy($__vInterCommunicationAPI[$__iInterCommunicationControlID]) EndFunc   ;==>_WM_COPYDATA Func _WM_COPYDATA_GetData()     Local $sReturn = $__vInterCommunicationAPI[$__sInterCommunicationData]     $__vInterCommunicationAPI[$__sInterCommunicationData] = ''     Return $sReturn EndFunc   ;==>_WM_COPYDATA_GetData Func _WM_COPYDATA_GetGUI()     Return $__vInterCommunicationAPI[$__hInterCommunicationGUI] EndFunc   ;==>_WM_COPYDATA_GetGUI Func _WM_COPYDATA_GetID()     Return $__vInterCommunicationAPI[$__sInterCommunicationIDString] EndFunc   ;==>_WM_COPYDATA_GetID Func _WM_COPYDATA_Send($sString)     If _WM_COPYDATA_GetGUI() = -1 Then         Return SetError(1, 0, 0)     EndIf     If StringStripWS($sString, 8) = '' Then         Return SetError(2, 0, 0)     EndIf     If _WM_COPYDATA_GetGUI() Then         Local $tData = DllStructCreate('wchar[' & StringLen($sString) + 1 & ']')         DllStructSetData($tData, 1, $sString)         Local Const $tagCOPYDATASTRUCT = 'ulong_ptr;dword;ptr'         Local $tCOPYDATASTRUCT = DllStructCreate($tagCOPYDATASTRUCT)         DllStructSetData($tCOPYDATASTRUCT, 1, 0)         DllStructSetData($tCOPYDATASTRUCT, 2, DllStructGetSize($tData))         DllStructSetData($tCOPYDATASTRUCT, 3, DllStructGetPtr($tData))         _SendMessage(_WM_COPYDATA_GetGUI(), $WM_COPYDATA, 0, DllStructGetPtr($tCOPYDATASTRUCT))         Return Number(Not @error)     EndIf EndFunc   ;==>_WM_COPYDATA_Send Func _WM_COPYDATA_SetGUI($vGUI)     $__vInterCommunicationAPI[$__hInterCommunicationGUI] = $vGUI EndFunc   ;==>_WM_COPYDATA_SetGUI Func _WM_COPYDATA_SetID($sIDString)     $__vInterCommunicationAPI[$__sInterCommunicationIDString] = $sIDString     Return $sIDString EndFunc   ;==>_WM_COPYDATA_SetID Func _WM_COPYDATA_Shutdown()     Local $hHandle = WinGetHandle(AutoItWinGetTitle())     GUIRegisterMsg($WM_COPYDATA, '')     GUIDelete(_WM_COPYDATA_GetGUI())     ControlSetText($hHandle, '', ControlGetHandle($hHandle, '', 'Edit1'), '') EndFunc   ;==>_WM_COPYDATA_Shutdown Func _WM_COPYDATA_Start($hGUI, $fCheckOnly = Default)     Local $hHandle = WinGetHandle(_WM_COPYDATA_GetID())     If @error Then         If $fCheckOnly Then             Return 0         EndIf         AutoItWinSetTitle(_WM_COPYDATA_GetID())         $hHandle = WinGetHandle(_WM_COPYDATA_GetID())         If IsHWnd($hGUI) = 0 Or $hGUI = Default Then             $hGUI = GUICreate('', 0, 0, -99, -99, '', $WS_EX_TOOLWINDOW)             GUISetState(@SW_SHOW, $hGUI)         EndIf         ControlSetText($hHandle, '', ControlGetHandle($hHandle, '', 'Edit1'), $hGUI)         GUIRegisterMsg($WM_COPYDATA, '_WM_COPYDATA')         _WM_COPYDATA_SetGUI(-1)         $__vInterCommunicationAPI[$__iInterCommunicationControlID] = GUICtrlCreateDummy()         Return $__vInterCommunicationAPI[$__iInterCommunicationControlID]     Else         $hHandle = HWnd(ControlGetText($hHandle, '', ControlGetHandle($hHandle, '', 'Edit1')))         _WM_COPYDATA_SetGUI($hHandle)         Return SetError(1, 0, $hHandle)     EndIf EndFunc   ;==>_WM_COPYDATA_Start

Example use of Function:
AutoIt         
#include <GUIConstantsEx.au3> #include 'WM_COPYDATA.au3' _WM_COPYDATA_SetID('BAC92AA6-FDD8-11E1-91FF-3EE2937D8BEC') Example() Func Example()     Local $iControlID = _WM_COPYDATA_Start(Default) ; Start the communication process.     If @error Then         If Not _WM_COPYDATA_Send($CmdLineRaw) Then ; Send $CmdLineRaw if there is process already running.             MsgBox(4096, '2nd Instance: ' & @AutoItPID, 'Seems there was an @error, but more than likely $CmdLineRaw was blank.')         EndIf         Exit     EndIf     While 1         Switch GUIGetMsg()             Case $iControlID ; If the WM_COPYDATA message is interecepted then show the optimise function.                 _Optimise()         EndSwitch     WEnd     _WM_COPYDATA_Shutdown() EndFunc   ;==>Example Func _Optimise()     Return MsgBox(4096, '1st Instance: ' & @AutoItPID, _WM_COPYDATA_GetData()) ; Get the WM_COPYDATA file. EndFunc   ;==>_Optimise

Edited by guinness, 31 December 2012 - 11:41 AM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013






#2 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,512 posts

Posted 10 September 2010 - 11:19 AM

$TEMPCOPYDATA = DllStructCreate("ulong_ptr;dword;ptr", $lParam)


#3 guinness

guinness

    guinness

  • MVPs
  • 10,273 posts

Posted 10 September 2010 - 11:31 AM

Thanks ever so much, I replaced all instances of "dword;dword;ptr" to "ulong_ptr;dword;ptr" and now it works in both x32 & x64 versions.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#4 guinness

guinness

    guinness

  • MVPs
  • 10,273 posts

Posted 12 September 2010 - 02:35 PM

I updated the original post by adding encryption to the data that is sent between both programs and tidied up WM_COPYDATA_SENDDATA().

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users