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
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Fri Nov 30, 2007 1:29 pm    Post subject: Reply with quote

Well, It seems that first test was not so good. I switched back to Lex's version as I can't get away from "file not found" and it works equaly fast .... don't know why it was slow the first time, probably my bad.

Anyway, Lex version is much less prone to file not found, it almost never happens.... I can't understand why.... I even used extremes, like critical 80000 but nothing changed. I think that critical doesn't influence the Seans version as DDE message is encapsulated by operating system, which is not the case in Lex's wrapper.

However, even with Lex's version message still appears, randomly, even when DDE_InitServer is very first command in the script. Even worst, my current script behaves better when I call InitServer after initialising other components....

Perhaps the problem lays in the fact that AHK needs to launch and process its own command line, parse the script, create its own window, etc... then execute the script. During that time there are probably places where Explorer gets a chance to return, and if that is the case, the thing seems unfixable.

I don't know, I am very random results - sometimes I don't get anything at all, sometimes every 2nd launch produces an error. Moving DDE_Init up and down in the script changes behavior. Latest, "most stable" version of my scripts looks like:

Code:
   critical 8000
   InitApp(), GuiCreate(), GuiInit(), DDE_Init()
   critical off
   Sleep, -1


There is also a thing here that I can not initialize DDEServer before my application is ready to process files. If I start DDEServer too soon, messages are interupting initialization on weird places.

For now above code doesn't produce errors. I will test it extensively in next days to see if it is gone or not...
_________________
Back to top
View user's profile Send private message MSN Messenger
Lexikos



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

PostPosted: Fri Nov 30, 2007 3:53 pm    Post subject: Reply with quote

majkinetor wrote:
don't know why it was slow the first time, probably my bad.
Yeah, probably. Laughing

Anyway, I just tested with 440 files, and it took 20 seconds, giving an average of 45ms per file. Then I removed the GUI from my test server, instead outputing to the console... now 15 seconds (34ms average.)

I had to launch the files in a loop via AutoHotkey, since Vista disables the "Open" action when I select > 15 files. Mad (A very reassuring feature, actually. Ever hit Enter by accident with 1000+ files selected? Evil or Very Mad )

Keep in mind that the script only returns from WM_DDE_EXECUTE after the subroutine finishes.
Quote:
Acctually, I can not make it to work without displaying File not found message no matter what I do (talking about Seans version now).
Usually that message means that no DDE Server(s) responded to the "initate" message. It may happen if Explorer returns from WaitForInputIdle() before the DDE Server is finished initializing. WaitForInputIdle() usually returns (I think) when AutoHotkey checks for messages; hence Critical 500.

When I was writing my script (before I added Critical 500), it happened consistently for the first file, but once the script started it worked perfectly.


Perhaps related to WaitForInputIdle, it seems if the DDE server checks for messages from the execute handler, Explorer goes on to the next file (or at least AutoHotkey's Run command returns.) At first I thought it was just taking too long to process, however...
Code:
DllCall("Sleep","uint",1000)
With this in my execute handler, the server received 99 of 100 files - the client apparently waited for each one (except for one?)
Code:
Sleep, 1000
With this in the execute handler, the server received 4 of 100 files. The difference is that Sleep allows AutoHotkey to check for messages, whereas Sleep() simply suspends all activity in the current thread.

Actually, I just noticed this on the Critical help page:
Quote:
However, commands that wait such as Sleep and WinWait will check messages regardless of this setting (a workaround is DllCall("Sleep", Uint, 500)).
Rolling Eyes

Have you tried adding Critical,N to DDE_OnExecute()?
majkinetor wrote:
During that time there are probably places where Explorer gets a chance to return, and if that is the case, the thing seems unfixable.

MSDN wrote:
The WaitForInputIdle function enables a thread to suspend its execution until the specified process has finished its initialization and is waiting for user input with no input pending.
Perhaps we could somehow "stall" message processing some other way, or loop input messages back into the message queue.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1337

PostPosted: Fri Nov 30, 2007 3:55 pm    Post subject: Reply with quote

majkinetor wrote:
I can't get away from "file not found"

It's not certain to me exactly what stage the error message is produced at. I tested with my server/client scripts specifying a wrong path for sData in the client script. Just nothing happened without any error message. So, I suggest to add the following line at the start of the callback function DDE_Callback() for debugging:
Code:
MsgBox, % """" . DDE_GetData(hData) . """"
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Fri Nov 30, 2007 4:39 pm    Post subject: Reply with quote

Quote:
When I was writing my script (before I added Critical 500), it happened consistently for the first file, but once the script started it worked perfectly.

The very same here BUT only when selection contains single file. If selection contain multiple files, it works OK. All this happens when script is not running. When script is running, those errors never appear in either your or Seans version. It still doesn't happen on my jobs computer with the latest code I showed, but I will check at home some more.

Quote:
Perhaps we could somehow "stall" message processing some other way, or loop input messages back into the message queue.

That is exacly what I wanted to achieve with code like:

Code:
  critical 800000   ;using some very large value here
  ;arbitrary code here without sleep and WinWait
  critical off


Code:
Have you tried adding Critical,N to DDE_OnExecute()?

Nope.

Sean wrote:
It's not certain to me exactly what stage the error message is produced at
Its produced only on single file action when script is not running.
_________________
Back to top
View user's profile Send private message MSN Messenger
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Fri Nov 30, 2007 5:49 pm    Post subject: Reply with quote

Unfortunately, at home, at slower computer error continues poping up, not that frequent and again only on single file action....
_________________
Back to top
View user's profile Send private message MSN Messenger
Sean



Joined: 12 Feb 2007
Posts: 1337

PostPosted: Sat Dec 01, 2007 1:24 am    Post subject: Reply with quote

I never tested it with the shell as I don't like to write to the registry, I don't even have a registry entry for .ahk.
Have to tweak the registry as following to be used with my DDE.ahk:
Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.testfile]
@="AutoHotkeyDDE"

[HKEY_CLASSES_ROOT\AutoHotkeyDDE\shell\open\command]
@="\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\" \"D:\\DDE.ahk\" \"%1\""

[HKEY_CLASSES_ROOT\AutoHotkeyDDE\shell\open\ddeexec]
@="\"%1\""

[HKEY_CLASSES_ROOT\AutoHotkeyDDE\shell\open\ddeexec\Application]
@="AutoHotkey"

[HKEY_CLASSES_ROOT\AutoHotkeyDDE\shell\open\ddeexec\Topic]
@="EXECUTE"
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Sat Dec 01, 2007 1:37 am    Post subject: Reply with quote

The speed problem is really interesting. I noticed that winamp when you select "Play in Winamp" imediataley add all selected mp3s in the list. It uses DDE for that. So, adding 20 mp3s in ahk takes like 2s, while the same thing in WInamp is instant.
_________________
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 1:46 am    Post subject: Reply with quote

Sean wrote:
It's not certain to me exactly what stage the error message is produced at. I tested with my server/client scripts specifying a wrong path for sData in the client script.
See The Old New Thing: Psychic debugging: Understanding DDE initiation.

"Windows cannot find 'file'" in this case really means "Windows could not initiate a DDE connection, but is too hopeless to give a useful error message."
majkinetor wrote:
The speed problem is really interesting. I noticed that winamp when you select "Play in Winamp" imediataley add all selected mp3s in the list. It uses DDE for that. So, adding 20 mp3s in ahk takes like 2s, while the same thing in WInamp is instant.

As I tried to say before, what the DDE server does when it receives a command directly affects how fast it processes the messages (and how fast Explorer sends them.)
I wrote:
Keep in mind that the script only returns from WM_DDE_EXECUTE after the subroutine finishes.


Last edited by Lexikos on Sat Dec 01, 2007 2:15 am; edited 2 times in total
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1337

PostPosted: Sat Dec 01, 2007 1:48 am    Post subject: Reply with quote

majkinetor wrote:
The speed problem is really interesting. I noticed that winamp when you select "Play in Winamp" imediataley add all selected mp3s in the list. It uses DDE for that. So, adding 20 mp3s in ahk takes like 2s, while the same thing in WInamp is instant.

Could you post the registry entry for .mp3. Although I don't really know if it's possible with ddeexec, I reckon WinAmp accepts multiple files as a single whole entry (i.e. single ddeexec), not as separate one-by-one entries.


Last edited by Sean on Sat Dec 01, 2007 1:50 am; edited 1 time in total
Back to top
View user's profile Send private message
TerrapinII



Joined: 20 Nov 2007
Posts: 7
Location: usa

PostPosted: Sat Dec 01, 2007 1:50 am    Post subject: Reply with quote

I'm not sure why no one seems to have read my solution. Although someone found it or suggested they did.

I kept having the 'file not found' error once in a while. I added right after initializing the server, a 'sleep 50'. I've been using this possibly hundreds of times since, and have never had that error again. I believe it is due to sleep checking the message queue.

It does take a little while to load 20-30 files, so I make a transparent window (just text) which is superimposed, and says 'loading files...' followed by an incrementing counter for each file loaded. That way, the perception of time is very quick.

There is some other way to do this besides DDE, I do not know what it is. But I have programs which load many files very quickly, and have no registry entries for dde.

When using DDE, I never get a complaint or warning for my app when loading 50+ files. Explorer understands that DDE is being used. Probably the difference is that I *do* set up the DDE config in the registry.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1337

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

Sean wrote:
I reckon WinAmp accepts multiple files as a single whole entry (i.e. single ddeexec), not as separate one-by-one entries.

It just occurred to me that I might have done a similar thing. May try after replacing %1 with %L. I think %L stands for List, but not so sure. If it's so, the list may be null separate strings.
Back to top
View user's profile Send private message
Lexikos



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

PostPosted: Sat Dec 01, 2007 2:20 am    Post subject: Reply with quote

TerrapinII wrote:
I still occasionally had problems (this is somewhat a part I did not understand) with the server not being ready for the first file with a launch. I sometimes was getting the message of the file not being found. I solved it by placing a Sleep 50 after calling the initialization. I think maybe the reason this works is that it forces the script to then immediately check the message queue.

I think perhaps I disregarded that part of your post because it made no sense to me. Mad AutoHotkey goes into a message loop (i.e. continuously checks for messages) as soon as the script finishes initializing. I can't see why adding Sleep would help. (But then, in all of my tests Critical 500 was sufficient for everything to work.)

Btw, I benchmarked the script again; this time with 10 files, repeated 100 times. For both scripts (Sean's and mine), using an AutoHotkey loop gave a result of 31 seconds, while using a batch file gave 28 seconds. For both, all 1000 files were received (I used Critical 500 in the auto-exec of Sean's script.)
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1337

PostPosted: Sat Dec 01, 2007 2:37 am    Post subject: Reply with quote

lexikos wrote:
See The Old New Thing: Psychic debugging: Understanding DDE initiation.

Thanks. Always interesting place to visit.

Quote:
"Windows cannot find 'file'" in this case really means "Windows could not initiate a DDE connection, but is too hopeless to give a useful error message."

I suppose this error message with my DDE.ahk was caused by using incorrect Application name, which should be simply AutoHotkey, so it couldn't find the server to talk, nothing to connect.
After replacing the registry entry with the one I posted, I haven't got any error message at all so far in my system.
Back to top
View user's profile Send private message
Lexikos



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

PostPosted: Sat Dec 01, 2007 2:49 am    Post subject: Reply with quote

%L seems to "work," in that it still launches the file. Unfortunately, it also still initiates one DDE connection per file, rather than executing all at once.

I tried the benchmark on my XP virtual machine... 29 / 25 seconds Shocked. I thought something must've changed, so ran it again on Vista (with Virtual PC still running), and got 43 / 37 seconds. ShockedShocked
Quote:
I suppose this error message with my DDE.ahk was caused by using incorrect Application name,
That would do it. Smile
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1337

PostPosted: Sat Dec 01, 2007 3:37 am    Post subject: Reply with quote

lexikos wrote:
%L seems to "work," in that it still launches the file. Unfortunately, it also still initiates one DDE connection per file, rather than executing all at once.

We better wait for the registry entry of WinAmp's mp3.

As a side note, I wrote DDE.ahk as the standard library around the time of COM.ahk even though there was no need of it, which wasn't coincidental.
As you can see, the syntax of DDEML strikingly resembles that of COM. It just appeared to me as, say COM v0.1.
Now, your example of .NET, more specifically COR, appears to me sort of as COM v2.0...
Back to top
View user's profile Send private message
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 2 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