Page 1 of 4

XYplorer Messenger - Rev. 1.20 / 2013/02/08

Posted: 06 Feb 2013 12:12
by Marco
[This first post gets updated from time to time, particularly when a new revision is released. You are strongly advised to read this post carefully!]

Latest release notes

Code: Select all

Rev. 1.20 / 2013/02/08
 * A NULL character was appended to every command, leading
   to unpredictable results. Fixed.
A little executable that remotely controls XYplorer by sending it messages (hence the name) using the WM_COPYDATA command.

Features

[*]Open source: the AutoIt v3 code is available below.
[*]Customizable: all the parameters are neatly gathered on top, so you could tweak this basic utility to work with other applications.
[*]No external dependencies: all the necessary code is contained inside the script.

General structure

The first four lines of the script contain the working parameters, namely

[*]$Script: the command that will be passed to XYplorer. According to XYplorer 12.00 help, page 305,
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 ::).
[*]$WM_COPYDATA: the identifying code of such Windows command.
[*]$hWnd: the handle of XYplorer window, which is identified by its class, i.e. "ThunderRT6FormDC".
[*]$dwData: another parameter, set according to the aforementioned help file.

Follows service code to parse all these parameters and then send the desired message.

Usage

Technically, you run the compiled executable with the desired script as parameter, following the rules quoted above. Period.
Try starting XY and minimizing it. Then create a shortcut to the executable, set the target like this and see what happens...

Code: Select all

"C:\path\xyplorer_messenger.exe" :: $Freddie = "Who wants<crlf>to live<crlf>forever?"; text $Freddie
But my psychic powers are telling me that 99% of you is still thinking "WTF?". So I better describe my real-world usage scenario. Quick background can be found at http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=9205 and http://forum.voidtools.com/viewtopic.php?f=2&t=1643 . Everything (the MFT search engine) requires admin privileges, but I run under a limited account. So whenever I double click on a item among the search results an elevated instance of the related software (Winamp for mp3's, Word for docx's) is run. And that's no good. But here comes the trick where this code comes in handy. I always have a running XYplorer instance as limited user in background, and I set these values in Everything's ini file:

Code: Select all

explore_folder_command=$exec("C:\path\XYplorer\XYplorer.exe" "%1")
open_folder_path_command=$exec("C:\path\XYplorer\XYplorer.exe" "%1")
explore_folder_path_command=$exec("C:\path\XYplorer\XYplorer.exe" "%1")
open_file_command=$exec("C:\path\xyplorer_messenger.exe" ::open "%1")
open_folder_command=$exec("C:\path\xyplorer_messenger.exe" ::open "%1")
The first three lines tell Everything to explore paths with XYplorer: XYplorer will popup showing the content of the selected folder.
The last two lines instead tell Everything that, upon double click on a file or folder, the path should be embedded in a ::open "path" quick script and passed as a parameter to the messenger, which will in turn send this message to XYplorer.
Bottom line benefits:
-no more elevated instances of various software
-no more XYplorer window popping up unnecessarily
-you can use your PFAs!

Tested on

* Microsoft® Windows® 7 Ultimate SP1 x64 ITA

Requirements

* XYplorer with
- scripting enabled

Notes


* :!: :!: :!: I absolutely take no responsibility for whatever damage, direct or indirect, the usage of this script may cause. This code is provided as-is, use at your own risk. You are advised.

Possible future updates

* Switching to C/C++/C#, which should provide faster execution times;

Previous releases notes

Code: Select all

Rev. 1.10 / 2013/02/07
 * Now the command to be passed is handled verbatim.
   This means no more quotes hell.

Rev. 1.00 / 2013/02/06
 * The first version.
 :D :D :D Special thanks to...

* http://rainmeter.net/cms/Developers-API-WindowMessage, for providing the AutoIt v3 code base
* Channing, who indirectly suggested to identify XYplorer window by its class

Code

Code: Select all

$Script = $CmdLineRaw
$WM_COPYDATA = 0x004A
$hWnd = WinGetHandle("[CLASS:ThunderRT6FormDC]")
$dwData = 0x00400001

$iSize = StringLen($Script)
$pMem = DllStructCreate("wchar[" & $iSize & "]")
DllStructSetData($pMem, 1, $Script)

$pCds = DllStructCreate("dword;dword;ptr")
DllStructSetData($pCds, 1, $dwData)
DllStructSetData($pCds, 2, ($iSize * 2))
DllStructSetData($pCds, 3, DllStructGetPtr($pMem))

DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($pCds))
Compiled code

Code: Select all

xyplorer_messenger.exe 
Size  : 302.343 byte
MD5   : 1a4c4683955c4838411d8d69908de16d
SHA-1 : 351962b54a0846b94cd0460fa6cfbccf6472dbb9
CRC32 : 1139DEA9

xyplorer_messenger.zip 
Size  : 286.858 byte
MD5   : f6b80b8f648811ccf79b3b27929f953a
SHA-1 : 780500ca68a806ab7a0adccec191ecd9ae90376f
CRC32 : 207C03D6

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 06 Feb 2013 18:20
by serendipity
Thanks Marco!!
I wanted to give a shot at $WM_COPYDATA too, now i don't have to.
Will try this and report back.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 06 Feb 2013 18:26
by Marco
serendipity wrote:Thanks Marco!!
I wanted to give a shot at $WM_COPYDATA too, now i don't have to.
Will try this and report back.
And if you know C you could rewrite it, so the exe size can be squeezed down to a couple of kbs.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 06 Feb 2013 18:42
by TheQwerty
This is really impressive Marco!
I can't say I have a need for it or plan to use it anytime soon, but it's some fantastic work. :appl:

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 06 Feb 2013 18:48
by Marco
TheQwerty wrote:This is really impressive Marco!
I can't say I have a need for it or plan to use it anytime soon, but it's some fantastic work. :appl:
Thank you. My usage scenario so far is the one I described above... Don spoils us all with fast paced beta releases, so I fear that the other developer might take a lot to change his program architecture. "A lot" according to the standards we are used over here :mrgreen:
So I had to do something, and here it is.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 06 Feb 2013 21:22
by Marco
Don, all of the sudden PFAs don't work with this technique. In XY I associated *.maff files with Firefox and here's what happens:
-if I past in the address bar ":: open C:\sample.maff" the file is opened by XY as expected
-if I send ":: open C:\sample.maff" via WM_COPYDATA I get that Windows little message that estension is not recognized blah blah blah
Can you repro? It worked till 6 hours ago. Also tried a fresh install, no luck...

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 08:36
by admin
I'm not aware of any changes. :|

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 10:52
by admin
Did you already recheck with 12.00.0000?

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 11:05
by Marco
Yes, just rechecked with a fresh 12.00.0000 to which I just added said PFA, still no luck. Unfortunately I don't have another computer to test, that's why I asked if you could repro. I even rebooted, because you never can tell.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 11:13
by admin
Tell me exactly how I should test this.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 11:39
by Marco
Ok.

Requirements: XY 12.00.0000 (from homepage), XYplorer Messenger 1.00 (from the zip on the first post)

Steps:

0. Unpack XYplorer and unpack XYplorer Messenger
1. In the folder where you unpacked XYplorer Messenger create a file called new.cue. Such file should have a blank icon and upon double click should trigger the "unrecognized extension" message by Windows.
2. Still in said folder, create a link to the messenger, and in the properties set the target as

Code: Select all

C:\path\xyplorer_messenger.exe ":: open ""C:\path\new.cue"""
3. Open XYplorer and create this PFA

Code: Select all

cue>notepad
4. Now double click the link created at step 2. While you should see the notepad, but you get the unrecognized extension message instead. Typing in the address bar

Code: Select all

:: open "C:\path\new.cue"
works as expected tho.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 12:00
by admin
Confirmed.

See the trailing quote in the message. Some parsing issue...

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 12:09
by Marco
That's strange because I don't see any odd quotes
Immagine.png
Immagine.png (28.78 KiB) Viewed 16760 times

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 12:28
by admin
Totally weird. If I use a known extension (eg *.txt) I see no odd quotes and it works as expected (file is openend). Buffling.

Re: XYplorer Messenger - Rev. 1.00 / 2013/02/06

Posted: 07 Feb 2013 13:47
by Marco
Ok, 99% solved. I notice that

Code: Select all

C:\path\xyplorer_messenger.exe ":: open ""C:\path\new.cue"","
(mind the comma) works as expected. Do your magic now!
PS: I'm going to publish an updated code (actually just one word) that will send the message to XY raw/verbatim, so there's no quoting hell involved.