AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DDE Server (for single-instance file association) [std-lib]
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Sat Dec 01, 2007 9:59 am    Post subject: Reply with quote

I did the test myself with 21 files, and I used OutputDebug with DebugView. It took 400ms in total to populate DebugView.
BTW, SetBatchLines, Fast, CBF_SKIP_ALLNOTIFICATIONS actually didn't affect the time. Maybe an artifact of using/interacting dbgview.exe.
And, notice that I didn't use Critical which made AHK irresponsive a while in the test.

Code:
#Persistent
SetBatchLines, -1
OnExit, DdeClose

idInst   := DDE_Initialize(0, pfn:=RegisterCallback("DDE_Callback", "Fast"), 0x003C0000)   ; CBF_SKIP_ALLNOTIFICATIONS
bSucc   := DDE_NameService(idInst, "AutoHotkey", 1)
Return

DdeClose:
DDE_NameService(idInst, "AutoHotkey", 2)
DDE_Uninitialize(idInst)
ExitApp

DDE_Callback(nType, nFormat, hConv, hString1, hString2, hData, nData1, nData2)
{
   If   nType = 0x4050                  ; XTYP_EXECUTE
   {
      OutputDebug, % DDE_GetData(hData)
      DDE_FreeDataHandle(hData)
      Return   0x8000
   }
   Else If   nType = 0x1062                  ; XTYP_CONNECT
      Return   True
}


PS. BTW, I got the same result with lexikos's script too.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Sat Dec 01, 2007 11:45 am    Post subject: Reply with quote

Ok, I made us single testing application so we can share test results.

Download

About the test app
  • You will register DDE if you click "Register DDE" checkbox. This will add "ADD TO TEST AHK LIST" context menu entery for every file and folder in the system. It will stay in effect when you exit application so you can test DDE when script is not running. You can uninstall it anytime if you uncheck this box.
  • There are both dde versions in the test file, by default Lex's version is enabled. To enable Seans version, simply uncomment code in DDE_Init() function.

It would be good to link this on first page so people intersted in this can see it in action without messing around.

2Sean

_________________
Back to top
View user's profile Send private message MSN Messenger
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Sat Dec 01, 2007 12:26 pm    Post subject: Reply with quote

majkinetor wrote:
2Sean

Thanks. I vaguely recalled meanwhile the shell doesn't support the list of files, always one-by-one, and %L stands for LongFile name... Sorry for causing the confusion, it's been so long I ever messed with the registry.

This led me to test with DebugView as then there seemed to be no reason WinAmp could do it any faster. I believe the difference comes when they fill the list view with the file names. Or, IIRC, I think WinAmp is using plugin for DDE, so it might be essentially multi-thread vs single-thread.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Sat Dec 01, 2007 4:34 pm    Post subject: Reply with quote

Yes, %L works like that in Total Commander, not in Explorer Smile


About Winamp case, there is something to note: winamp creates 3 enteries, Add, Enqueue and Bookmark. They all have the same DDE setup, except command field - Enqueue has "/ADD" parameter before %1 and Bookmark has "/BOOKMARK". I wonder how does it work if Winamp is already started,as DDE setup is the same for all 3. So if Winamp is already active, command never gets executed, so Winamp doesn't receive /ADD and /BOOKMARK cmd line options.

I used test app from above to add 2000 files in the list (entire systm32 folder) I activated menu item from Total Commander. The strange thing is that TaskInfo started to complain after few seconds about large number of GDI objects ??? TC had 6K and SYstem had 7K objects after some time. SYstem became very unresponsive, TC was eating a lot of CPU and once operation finished (all files aded) system blocked .... Strange shit.
_________________
Back to top
View user's profile Send private message MSN Messenger
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Sat Dec 01, 2007 8:41 pm    Post subject: Reply with quote

majkinetor wrote:
I wonder how does it work if Winamp is already started,as DDE setup is the same for all 3. So if Winamp is already active, command never gets executed, so Winamp doesn't receive /ADD and /BOOKMARK cmd line options.
Check for a "DropTarget" registry key. I think that only works on XP and later, though... I haven't been able to find much info on it, but it is mentioned on Verbs and File Associations.
MSDN wrote:
The DDE method is being deprecated; use the DropTarget method instead. The DropTarget method is more robust and has better activation support since it uses Component Object Model (COM) activation of the handler. In the case of multiple item selection, it is not subject to the buffer size restrictions found in both DDE and CreateProcess. Also, items are passed to the application as a data object that can be converted to an item array by using SHCreateShellItemArrayFromDataObject. This provides an easier programming model for the items and does not lose namespace information as happens when the item is converted to a path for command-line or DDE protocols.
I think it requires a COM server, though, so probably not possible with AutoHotkey.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Sat Dec 01, 2007 10:54 pm    Post subject: Reply with quote

so, any ideas ?
_________________
Back to top
View user's profile Send private message MSN Messenger
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Sun Dec 02, 2007 1:15 am    Post subject: Reply with quote

lexikos wrote:
I think it requires a COM server, though, so probably not possible with AutoHotkey.

I suppose DropTarget can be the simplest COM Local Server. Just call CoRegisterClassObject at the start-up of the script, and CoRevokeClassObject at the exit. And it only needs to implement two interfaces, IClassFactory which is really simple and IDropTarget which has been done in my DragDrop.ahk. The CLSID to be registered in the registry can be obtained using CoCreateGuid etc, and writing the CLSID registry key is straightforward, I think. One thing I'm not sure atm is whether it will work with both uncompiled and compiled scripts, or only with a compiled one.

Of course it's only an idea at this stage, can't really tell for sure until actually tackle it. If no one does it already, I may tackle it myself next weekend.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Sun Dec 02, 2007 1:47 am    Post subject: Reply with quote

majkinetor wrote:
I wonder how does it work if Winamp is already started,as DDE setup is the same for all 3.

Are the Application and/or Topic names the same too?

Quote:
I used test app from above to add 2000 files in the list (entire systm32 folder) I activated menu item from Total Commander. The strange thing is that TaskInfo started to complain after few seconds about large number of GDI objects ??? TC had 6K and SYstem had 7K objects after some time. SYstem became very unresponsive, TC was eating a lot of CPU and once operation finished (all files aded) system blocked .... Strange shit.

When I chose 21 files (in Total Commander) and excuted them through the context menu in my previous test, Windows produced a warning dialog telling something like "it could take longer time and slow down the system opening this many files at the same time, blah blah". I checked to not show this dialog again. Maybe you had done it already in your system.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Sun Dec 02, 2007 10:27 am    Post subject: Reply with quote

Quote:
If no one does it already, I may tackle it myself next weekend.

I would appricate that. I am far more interested if it can be made working with uncompiled scripts, but any working version will be good. IIRC, COM Server can be exe, and if that is the case, can't we just use the same line as in DDE case ("ahk.exe script")?

Quote:
Are the Application and/or Topic names the same too?

Yes. Like I said, all 3 items, has winamp as app and "system" as topoic, the only differnece is cmd line parameter.

Quote:
I checked to not show this dialog again. Maybe you had done it already in your system.

No. I let this thing be so I don't accidently execute some app multiple times. I click OK every time. BUt my point was more about how pinging the server and sending it few messages (in a loop) can do such thing to a system...
_________________
Back to top
View user's profile Send private message MSN Messenger
TerrapinII



Joined: 20 Nov 2007
Posts: 7
Location: usa

PostPosted: Mon Dec 03, 2007 4:27 am    Post subject: Reply with quote

I have a question or two, as I am using lexicos' DDE functon, and it is both interesting and it is important (adds functionality) to my project.

One, is, how can I have another application (totally external) pass my script DDE commands, or is this possible at all unless the external program supports it? The program I have in mind will simply allow you to define an app external to it, and it passes the filepaths to it.

I had wondered about causing Explorer to create an HDROP (which I don't know much about).. which the receiver would simply see as having had the user drag'n'drop the files. This is very easy to process with none of the worries. Another possibility is having the selected files copied to the clipboard (which is the same as an HDROP I think, for that type function). The use of that is, Autohotkey can get the filepaths right out of the clipboard as text, which would be very simple.

I don't know for sure about why 'sleep 50' works for me, but it does. Smile Also, I do not process anything until all files seem to have been received, I just collect the filepaths. I compared to other programs which receive files this way, and mine is no slower.

Thanks very much
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Mon Dec 03, 2007 8:10 am    Post subject: Reply with quote

majkinetor wrote:
I am far more interested if it can be made working with uncompiled scripts,

Actually I finished implementing it. I uploaded test version AutoHotkeyVerb.zip. First, unzip all 3 files in the same directory and execute RegisterVerb.ahk. It'll write the corresponding registry entries for the extension .test and AutoHotkeyVerb and COM Server CLSID. It'll display the filenames in DebugView.

Quote:
all 3 items, has winamp as app and "system" as topoic, the only differnece is cmd line parameter.

Then, I guess WinAmp always Unregister the server after each DDE Execute, then Register again on new DDE Execute. Or something similar.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Mon Dec 03, 2007 12:07 pm    Post subject: Reply with quote

This works like a charm with minimal code addition (if I don't count COM module). I tested with 2000 files and it added them instantly. I just scaned the Winamp registry enteries, and it uses DropTarget with winamp.exe as Server.

So this seems like a complete solution for this project - scripts requering no more then several files to be send can use original DDE, those requiring speed for multiple files must use DropTarget.

Thx for everything guys.
_________________
Back to top
View user's profile Send private message MSN Messenger
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Mon Dec 03, 2007 12:44 pm    Post subject: Reply with quote

Very interesting. I was not aware of CoRegisterClassObject. Now I wonder if proper desk bands may be created in AutoHotkey...
Edit: Guess not - "A band object must be registered as an OLE in-process server that supports apartment threading."
Interesting nonetheless.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1336

PostPosted: Mon Dec 03, 2007 1:52 pm    Post subject: Reply with quote

lexikos wrote:
Very interesting.

It may be more interesting to create IDispatch AutoHotkey COM Server, I suppose.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Mon Dec 03, 2007 2:21 pm    Post subject: Reply with quote

Quote:
Now I wonder if proper desk bands may be created in AutoHotkey

IMO, upgrading explorer is waste of time. Its badly designed from the start. There is even somewhere around pretty long esey describing all the points of Explorer's bad design.
_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group