Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WM_COPYDATA example (access application outside application)
#1
I am currently testing the file-manager XYplorer.

Xyplorer has the option to control it "outside" Xyplorer.

The manual gives the following info

Quote:You can run an XYplorer script from an external program using the WM_COPYDATA command with XYplorer's hWnd. This means if you are a programmer you can fully remote control XYplorer.
  • cds.dwData: 4194305 (0x00400001)

  • cds.lpData: The syntax is identical to the one of the command line switch /script=<script resource>, so you can either pass the path to a script file (commonly called *.xys), or pass the script directly (must be preceded by :Smile.

This is how you normally boot xyplorer and initiate script

Code:
Copy      Help
XYplorer.exe /script="f:\__windows_folders\_user\desk\test.xys"

I tried the following code (syntax)

Macro Macro2
Code:
Copy      Help
int hwnd=win("XYplorer")
if(!hwnd)    
,ret

COPYDATASTRUCT cds

cds.lpData="/script=''f:\__windows_folders\_user\desk\test.xys''"
cds.dwData=4194305

SendMessage(hwnd WM_COPYDATA cds.dwData cds.lpData)

I only wanted to know if the "SendMessage" has the correct syntax?

Or do I need to formulate it differently?
#2
Look in MSDN.
wParam must be sender window handle or 0.
lParam must be &cds.
cds.cbData must be specified. It is length of string, probably +1.

Macro Macro2104
Code:
Copy      Help
int hwnd=win("XYplorer")
if(!hwnd)    
,ret

str s="/script=''f:\__windows_folders\_user\desk\test.xys''"

COPYDATASTRUCT cds
cds.dwData=4194305
cds.lpData=s
cds.cbData=s.len+1

SendMessage(hwnd WM_COPYDATA 0 &cds)

Maybe the string must be Unicode UTF-16.
Macro Macro2104
Code:
Copy      Help
int hwnd=win("XYplorer")
if(!hwnd)    
,ret

BSTR b="/script=''f:\__windows_folders\_user\desk\test.xys''"

COPYDATASTRUCT cds
cds.dwData=4194305
cds.lpData=b.pstr
cds.cbData=b.len*2+2

SendMessage(hwnd WM_COPYDATA 0 &cds)
#3
Thank you very much!
This will help!

EDIT, update for others who want to experiment with xyplorer, use like this:

Macro XYplorer
Code:
Copy      Help
int w=win("XYplorer" "ThunderRT6FormDC") ;; window must be declared like this, or else it does not work

if(!w)    
,ret
,
;BSTR b="f:\__windows_folders\_user\desk\test.xys"  ;; If you want to use external XYplorer script
BSTR b="::msg ''Hello world!''" ;; If you want to run XYplorer script directly

COPYDATASTRUCT cds
cds.dwData=4194305
cds.lpData=b.pstr
cds.cbData=b.len*2+2

SendMessage(w WM_COPYDATA 0 &cds)
#4
Just a little update on this script, somehow the below line needed to be changed from 2+2 to 2+1
cds.cbData=b.len*2+1

And the BSTR with the script embedded had to be changed. It might be due to some update(s) within XYplorer.

If you do not apply these changes, the old method might not work or it might work but it will generate an scripting error message-box within xyplorer.

Macro Macro17
Code:
Copy      Help
;;; FULL PATH SCRIPT
;BSTR b="D:\test123\test.xys" ;; If you want to use external XYplorer script

;; PASS SCRIPT DIRECTLY (EMBEDDED)
BSTR b="::msg 'Welcome to XY!';"

COPYDATASTRUCT cds
cds.dwData=4194305
cds.lpData=b.pstr
cds.cbData=b.len*2+1
SendMessage(w WM_COPYDATA 0 &cds)
#5
Good stuff Ron,
Nice to see the interaction between XYPlorer and QM2 program. Big Grin
#6
Thank you!
#7
Very good example
#8
By any chance - has one of you managed to migrate this script over to LA?  Unfortunately I'm failing Sad
#9
not tested

Code:
Copy      Help
// script ""
var w = wnd.find("*XYplorer", "ThunderRT6FormDC");
if (w.Is0) return;
string s = "::msg ''Hello world!''";
WndCopyData.Send<char>(w, 0x00400001, s);
#10
Thank you VERY much! It didn't work, so I fiddled a bit with the wnd.find and used a statement that helped me before - and now it's working!  (I'll post the script in the LA forum Wink )


Forum Jump:


Users browsing this thread: 1 Guest(s)