Sending wm_copydata from ahk to c++ window Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Sending wm_copydata from ahk to c++ window

26 Sep 2021, 13:15

Sending the data from AutoHotkey with:

Code: Select all

   Send_WM_CopyData(StringToSend, WinTitle) {
               
      ; Set up the structure's memory area.
      VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)  
      
      ; First set the structure's cbData member to the size of the string, including its zero terminator:
      SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
      
      NumPut(SizeInBytes, CopyDataStruct, A_PtrSize)  ; OS requires that this be done.
      NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize)  ; Set lpData to point to the string itself.
      
      DetectHiddenWindows, On

      ; 0x4a WM_COPYDATA.
      TimeOutTime := 4000
      SendMessage, 0x4a, 0, &CopyDataStruct,, %WinTitle%,,,, %TimeOutTime%
      ; FileAppend, ErrorLevel: %ErrorLevel%`n,*

      ; Return SendMessage's reply back to our caller.
      return ErrorLevel
   }

Receiving on c++:

Code: Select all

    switch(msg)
    {
		case WM_COPYDATA:
		{
			OutputDebugString(L"\nWM_COPYDATA!");
			PCOPYDATASTRUCT pcds      = reinterpret_cast<PCOPYDATASTRUCT>(lParam);
			std::string received_data = (char*)pcds->lpData;

			std::string data = received_data;
			thread = std::async(std::launch::async, [data]
			{ InterpretReceivedData(data); });

			return 1;
		}
   }

However its being received just one character, if i send:
Send_WM_CopyData("abc", WinTitle)
It does receive a.

I could not find the type of the data being sent, if its a char, then im not sure if im receiving it correctly.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, DiegoSouto, mikeyww, robnicholson, Rohwedder, Swiftly9767 and 363 guests