wm_copydata CD path \0D path2 \0 "A" outcome random

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
dindog
Senior Member
Senior Member
Posts: 315
Joined: 2010-10-18, 07:41 UTC

wm_copydata CD path \0D path2 \0 "A" outcome random

Post by *dindog »

The cd command has an "A" parameter for if the path is an archive, put the cursor on it instead of opening it as a folder.
I test my AHK cd command, but the result is random and I can't find a pattern why sometime it opens the archive and sometime it isn't.

By contrast, TCFS2's send CD command with "A" parameter always works...
tcfs2 /ef "tcd(`E:\totalcmd950b7x64.cab`,``,A)"
so is TCMC
tcmc cdA "E:\totalcmd950b7x64.cab" ""

I made a wm_copydata receiver by AHK to logged the sent binary string to TC. the strange thing is, the string which open the archive and those didn't, are exactly the same.
I dumped the raw binary code:

Code: Select all

EF BB BF 45 3A 5C 74 6F  74 61 6C 63 6D 64 39 35 30 62 37 78 36 34 2E 63 61 62 0D EF BB BF 00 41 00 00 00

EF BB BF      45 3A 5C 74 6F  74 61 6C 63 6D 64 39 35 30 62 37 78 36 34 2E 63 61 62
UTF-8 BOM + E:\totalcmd950b7x64.cab
0D 
\r
EF BB BF 00 
UTF-8 BOM + ""
41 00 00 00
A
and here is the AHK code, test in TC9.5B6 64bit, Window 10 64bit, ahk_unicode32

Code: Select all

bom :=( A_IsUnicode )?Chr(0xFEFF):""
F1::
TC_SendData(bom "E:\totalcmd950b7x64.cab"`r" bom, "A")
return

/*
TESTED AND WORKING ON: AHK_L v1.1.21.03 UNICODE X32 + Win7 X32 + TC 8.51a
-------------------------------------------------------------------------
TC_SendData("C:\tc" "`r" "D:\data", "CD")	 ; CD   Command: (LeftDir - RightDir)
TC_SendData("C:\tc" "`r"          , "R")	 ; CD   Command: (LeftDir) and activate Right panel
TC_SendData(        "`r" "D:\data", "LT")	 ; CD   Command: (          RightDir) in new tab and activate left panel

TC_SendData("C:\tc" "`r" "D:\data", "S")	 ; CD   Command: (SourceDir - TargetDir)
TC_SendData("C:\tc" "`r"          , "SBT")	 ; CD   Command: (SourceDir) in new background tab
TC_SendData(        "`r" "D:\data", "ST")	 ; CD   Command: (            TargetDir) in new background tab
S: Interpret the paths as source/target instead of left/right
T: Open path(s) in new tabs
B: Open tabs in background (do not activate them)
L: Activate the left panel
R: Activate the right panel
A: Do not open archives as directories. Instead, open parent directory and place cursor on it.
TC accepts more then 2 parameters here, so sending e.g. STBL is legitimate.
*/
TC_SendData(Cmd, CmdType="", msg="", hwnd="") {
   Critical   ; Define "OnMessage" as STATIC it is registered at Script startup.
   STATIC om:=OnMessage(0x4a, "TC_SendData"), TC_ReceiveDataValue:="", TC_DataReceived:=""	; 0x4a is WM_COPYDATA

   IF ((msg=0x4A) AND (hwnd=A_ScriptHwnd)) ; EnSure is trigered by this Script.
      EXIT (TC_ReceiveDataValue:=StrGet(NumGet(CmdType + A_PtrSize * 2)), TC_DataReceived:="1")

   VarSetCapacity(CopyDataStruct, A_PtrSize * 3), TC_ReceiveDataValue:=1, TC_DataReceived:=""
   if (CmdType="") ; Ask TC
      CmdType:=(A_IsUnicode ? "GW" : "GA"), TC_ReceiveDataValue:=""
   else if (CmdType="EM") or (CmdType="em") ; em command
      CmdType:="EM"
   else  ; CD command STBALR
      DirType:=(CmdType="CD")?"":CmdType, CmdType:="CD"

      VarSetCapacity(cmdA, StrPut(cmd, (A_IsUnicode ?"UTF-8":"CP0")) + (CmdType="CD" ? 5 : 0) * (A_IsUnicode ? 2 : 1), 0)	,	Len:=StrPut(cmd, &cmdA, (A_IsUnicode ?"UTF-8":"CP0"))

   NumPut( Asc(SubStr(CmdType,1,1)) + 256 * Asc(SubStr(CmdType,2,1)), CopyDataStruct,0 )
   NumPut( Len + (CmdType="CD" ? 5 : 0) * (A_IsUnicode ? 2 : 1) , CopyDataStruct, A_PtrSize )
   NumPut( &cmdA , CopyDataStruct, A_PtrSize * 2)
   Loop, % strlen(DirType) ;(CmdType=="CD" ? 2 : 0)
   {  
      NumPut(Asc(SubStr(DirType,A_Index,1)), cmdA ,Len+A_Index-1, "Char")
      }
   SendMessage, 0x4A,%A_ScriptHwnd%, &CopyDataStruct,, ahk_class TTOTAL_CMD


; receiver ahk code:
Prev_DetectHiddenWindows := A_DetectHiddenWindows
    Prev_TitleMatchMode := A_TitleMatchMode
    DetectHiddenWindows On
    SetTitleMatchMode 2
   SendMessage, 0x4A,%A_ScriptHwnd%, &CopyDataStruct,, Receiver.ahk ahk_class AutoHotkey
   DetectHiddenWindows %Prev_DetectHiddenWindows%  ; Restore original setting for the caller.
    SetTitleMatchMode %Prev_TitleMatchMode%         ; Same.
; receiver ahk code end
   
   
   While (TC_ReceiveDataValue="") {
      IfEqual, TC_DataReceived,    1, Break
      IfGreaterOrEqual, A_Index, 500, Break
      Sleep,10
   }
   Return TC_ReceiveDataValue
}
receiver.ahk
It dumps the sent binary to D:\return.txt , but I actually use the clipboard by CLCL dump view to see the binary

Code: Select all

; Save the following script as "Receiver.ahk" then launch it:
#SingleInstance
OnMessage(0x4a, "Receive_WM_COPYDATA")  ; 0x4a is WM_COPYDATA
return

Receive_WM_COPYDATA(wParam, lParam)
{
    StringAddress := NumGet(lParam + 2*A_PtrSize)  ; Retrieves the CopyDataStruct's lpData member.
    CopyOfData := StrGet(StringAddress)  ; Copy the string out of the structure.


    len:=strlen(CopyOfData)
    Fh:=FileOpen("d:\return.txt", "rw")
    Fh.RawWrite(CopyOfData,len*2)
    Fh.close()
    
    clipboard:=CopyOfData

    ; Show it with ToolTip vs. MsgBox so we can return in a timely fashion:
    ToolTip %A_ScriptName%`nReceived the following string:`n%CopyOfData%
    return true  ; Returning 1 (true) is the traditional way to acknowledge this message.
}
Last edited by dindog on 2019-12-04, 07:17 UTC, edited 1 time in total.
User avatar
dindog
Senior Member
Senior Member
Posts: 315
Joined: 2010-10-18, 07:41 UTC

Re: wm_copydata CD path \0D path2 \0 "A" outcome random

Post by *dindog »

bump*
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: wm_copydata CD path \0D path2 \0 "A" outcome random

Post by *MVV »

Do you include null character at the end of WM_COPYDATA data into length? It should be included to ensure that TC gets flags string null-terminated.
Post Reply