AutoHotkey Community

It is currently May 27th, 2012, 4:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: March 7th, 2010, 4:41 am 
Offline

Joined: March 7th, 2010, 4:18 am
Posts: 5
Hi,

I'm trying to use DDE to send a word to a old Win 3.1 program (a dictionary), under Win XP.

I'm using Joy2DWorld's dde.ahk script, from here
http://www.autohotkey.com/forum/viewtopic.php?t=21910.

The code successfully opens the program, and displays the word definition I want, but I'm getting an error when I (try to) close the dictionary application. A rather old looking dialog box comes up saying:


Windows DDE

An application using DDE did not respond to the system's exit command.

* Choose Retry to attempt to close the application and return to Windows.
* Choose Continue to repeatedly attempt to close the application and return to Windows.
* Choose Close to exit the application that is not responding. You may lose any unsaved information in this application.


No matter which button I choose, the dictionary still appears in the task manager list (under KeyHH). I need to manually close it.

I'm a little uncertain if the "topic" I'm using is valid - but looking at an AmiPro macro provided with the dictionary, it appears to be a valid topic. I tried using the "System" topic to get a list of valid topics from the dictionary using DDE_Request - but printing the response with msgbox showed the response was empty.

Any ideas what's happening? Is DDE not disconnecting properly, preventing the dictionary from closing?

Thanks!

Here's my code:
Code:
RunNewSoed(wordToLookUp)
{
  ; Run (or activate) NewSOED (Seems to only have one instance since Win XP won't allow more than one instance of 16-bit app??)
  Run, c:\bin\NewSOED\NewSOED.exe, c:\bin\NewSOED

  if strlen(wordToLookUp) > 0
  {
    ; We have a word to lookup, use DDE
    DDE_connection := DDE_Connect("NewSOED","AmiPro")  ; NewSOED macros seem to allow AmiPro and WinWord6 as valid topics - so pick one...?
    ; msgbox %DDE_connection%              ; Displays something like: 20|0x70f76|0x530712
    result := DDE_Execute(wordToLookUp) 
    ; msgbox %result%                      ; Displays something like: 462710
    DDE_KILL()
  }
  return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 5:53 am 
With reference to your problem, I have had mixed results using the code you referenced (seemed to have timing problems with some apps).

However, I found the code posted by Sean (DDE.ZIP) in this post to be very reliable.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 2:00 pm 
Offline

Joined: March 7th, 2010, 4:18 am
Posts: 5
Thanks to whoever moved this to the right section.

Thanks for the tip about Sean's version - I had seen it, but gone with Joy2DWorld's because it seemed a little more complete, and not so task-specific.

Indeed, I'm somewhat confused by Sean's. In the DDEML.ahk file, I'm not sure which function to use to get DDE_Execute functionality.

And in DDEMessage.ahk, I worried that hWndClient and hWndServer aren't getting set (and whilst I could guess at hWndClient, I'm much less sure of the best way to set hWndServer).

Do you happen to know if DDE_EXECUTE works?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 4:21 pm 
qpkorr wrote:
Indeed, I'm somewhat confused by Sean's. In the DDEML.ahk file, I'm not sure which function to use to get DDE_Execute functionality.


DDE_ClientTransaction. is the function that actually does the DDE command, but you must initialize the conversation and set the parameters before calling it. (This is what I came up with for XMPlay using Sean's code as a template.
Code:
sName := "xmplay"
sTopic := "system"
sData = key80      ; toggle play/pause
sType   := "EXECUTE"

idInst := DDE_Initialize()
hConv  := DDE_Connect(idInst, sName, sTopic)
return := DDE_ClientTransaction(idInst, hConv, sType, sItem, &sData, StrLen(sData)+1) ; synchronous call
DDE_Disconnect(hConv)
DDE_Uninitialize(idInst)
msgbox, [%return%]
exitapp


qpkorr wrote:
And in DDEMessage.ahk, I worried that hWndClient and hWndServer aren't getting set (and whilst I could guess at hWndClient, I'm much less sure of the best way to set hWndServer).?

Don't know about hWndServer. It appears to be null (empty) thoughout the example code. All I can say about it is tbat the code works (getting a browser's current web page title).

qpkorr wrote:
Do you happen to know if DDE_EXECUTE works?
Somewhat. In the tests I did, the command was sent to the server (and executed), but it (the servers) were left in some wierd state - unable to accept futher commands until restarted. Also, the close conversation command (DDE_KILL()) consistently gave errors. These are the results of the tests I ran on Joy2DWorld's dde.ahk (I was going to post to Joy2Dworld's topic get help, but I found Sean's code worked well with the two applications I was controlling).
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; test of Joy2Dworld's client and xmplay server
name = XMPlay
topic = system
sData = key80      ; toggle play/pause

DDE_connection_Number1 := DDE_Connect(name,topic)
result := DDE_Execute(sData)
DDE_KILL(name,topic)
DDE_KILL()
msgbox, [%result%]
exitapp
#include %A_ScriptDir%\joy_dde.ahk
/*
XMPlay.exe errors (server accepts and completes command)
    but Joy2Dworld's client reports these errors:
       "++DDE UNDEFINED TERMINATION ERROR system|XMPlay  20 ** "
    also, returned value (%result%) is almost random
*/
;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; test of Joy2Dworld's client and launchpad server
name = LaunchPad
topic = commands
sData = [AddRunProgramEvent("Test","notepad","c:\win","Daily","12/03/96 12:34 am","VHB")]

DDE_connection_Number1 := DDE_Connect(name,topic)
result := DDE_Execute(sData)
DDE_KILL(name,topic)
DDE_KILL()
msgbox, [%result%]
exitapp
#include %A_ScriptDir%\joy_dde.ahk
/*
LaunchPad.exe errors (server accepts and completes command)
    but Joy2Dworld's client reports these errors:
       "UNDEFINED DDE EXECUTE  ERROR"
       and  "++DDE UNDEFINED TERMINATION ERROR commands|LaunchPad  20 ** "
       and leaves the server in unknown condition (will not accept more comands until restarted)
         (DDE client hangs in DDE_WaitA() when run for second time)
    also, returned value (%result%) is almost random
*/
;;;;;;;;;;;;;;;;;;;;;;


The biggest problem I had getting DDE to work, was getting the server name, topic, and commands correct (the required quoting was very confusing). I found two command line DDE utilities of great help getting everything correct, and when finished it all works reliably with Seans codes.

DDE_run.exe and CMCDDE (two freeware cmd-line DDE clients). Very useful for testing.


I hope some of this infomation helps you.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 12:24 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
its been a long time ...



DDE_KILL("SERVER_NAME","TOPIC", OPTIONAL_CONNECTION_NUMBER) *should* loop thru all connections and disconnect, when no params, but , would test with explicit server/topic and see if helps.

if so.. let me know and will look into where is bug in global release.



also set __DDE_SafeMode to value


(maybe try DDE_Poke in place of DDE_Execute ?)


hope helpful

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 1:51 am 
Offline

Joined: March 7th, 2010, 4:18 am
Posts: 5
First up, thanks so much for taking the time to reply so thoroughly. I really appreciate it.

Thanks also for your code sample for xmplay. The only problem with it seems to be that I think Sean has updated his dde stuff. I say this for two reasons - first, his function names now seem to be more like DdeInitialize, not DDE_Initialize. Second, there seem to be other changes, eg his DdeClientTransaction function is now taking the address of sData, so you probably don't need to in your function call.

The reason I'm saying this is that in trying to adapt your example to his new code, and my application, it's not working. The address of sData is one reason it mightn't work for me - but clearly there's some other reason I've not spotted.

Quote:
Don't know about hWndServer. It appears to be null (empty) thoughout the example code. All I can say about it is tbat the code works (getting a browser's current web page title).

True - except that hWndServer is only used in the functions DDE_POKE and DDE_EXECUTE, in DDEMessage.ahk - and as best I can tell, neither of these are called when getting the browser's current web page title.

I asked if DDE_EXECUTE works - which was meant to be a reference to DDE_EXECUTE in Sean's DDEMessage.ahk (since I was worried it wouldn't due to hWndServer). You appear to have responded regarding DDE_Execute, in Joy2DWorld's dde.ahk.

Regarding Joy's DDE_Execute - I had the same experiences. It worked for me too - but also left the servers in a weird state. You appear to call DDE_KILL twice - once with the name and topic, then with no arguments. In theory, either of these should do I think. I think it's the first call which is generating the "++DDE UNDEFINED TERMINATION ERROR system|XMPlay 20 ** " - as it did for me, so I changed to the second method, which had no error, but the 'weird state' was the same regardless. Re the first call, Joy tries to keep a record of all dde connections I think, and I suspect that maybe there's a bug there and it's not finding the named connection in his list. But I may be wrong, I've not managed to follow his code fully.

Quote:
The biggest problem I had getting DDE to work, was getting the server name, topic, and commands correct (the required quoting was very confusing).


I wonder if you could be kind enough to elaborate here. I think I understand that AHK has an equivalence between
var1 := "some text"
and
var1 = some text

OR

var2 := someVariable
and
var2 = %someVariable%

But I'm guessing you're referring to something else?

Thanks for the command line utilities, I'll check them out.

Quote:
I was going to post to Joy2Dworld's topic get help


For the record, I did write a PM to him asking for his assistance with this topic, as I rather liked the intent of his code, handling all connections for you etc - but no response yet.

Thanks again for your help - I'll keep trying, and maybe your command line utilities are just what I need.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 2:06 am 
Offline

Joined: March 7th, 2010, 4:18 am
Posts: 5
Oops! I spoke too soon, whilst I was replying Joy reappeared! Thanks! Yes, it was a while ago I know. Sorry to force your memory to work so hard!

As per my previous response, I like your approach re keeping track of connections etc. For my purposes at least, your approached seemed great.

I guess I have two main questions for you.

First - does DDE_KILL work properly for you, when you supply the server and topic? For both of us, it appears to give errors. It doesn't when called with no arguments.

Second - it's my impression that it's not fully terminating the DDE connection. For me, this manifests that when I try to kill the DDE server application (whilst the client, the ahk script, is still running), I get the error I posted originally, and the server app won't die fully. For our xmplay guest, it seems it's more that the server won't accept more commands. Does it still work for you?

Re __DDE_SafeMode - the help for it says
Quote:
__DDE_SafeMode = for multiple connection used at same time, etc. if set TRACKS MESSAGE INCOMING DATA AGAINST INTENDED CONNECTION and SERVER. This is **IMPORTANT** where you have data comming in from multiple servers and/or connections in NON-BATCH mode.

it makes sure that the answer you get actually comes from the CONNECTION and the SERVER you are expecting it to be from.


Personally, I have just one server in use, and my intention is to start the server, use it, kill the DDE connection, then probably kill the server app too. So multiple connections should be unnecessary. But I'll try it.

Re DDE_Poke - well, DDE_Execute is achieving the functionality I want, it's working (where I've not yet got things to work at all with Sean's code) - so I'm hesitant to change something that ain't broke! :)

Besides, isn't "poke" about writing something to memory somewhere (thinks back to GW BASIC days...) - I suspect if I want something to happen, Execute might be more what I want.

Thanks for your help!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 3:01 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
try watching __DDEM___DDE_Topic_List and __DDE_Server

and __DDE_Topic and __DDE_DDEConnection_

within the Kill function.



also could try setting true __DDE_Kill_window_on_Kill

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 3:47 am 
Offline

Joined: March 7th, 2010, 4:18 am
Posts: 5
Okay, problem solved perhaps. As best I can tell, your DDE_KILL function was referring to

__DDEM___DDE_Topic_List

where the others referred to

__DDEM_DDE_Topic_List

so nothing was ever getting terminated.

Grrr... does AHK have the equivalent of perl's "use strict" directive? Problems like this should be detected by computers, not humans...

On the plus side - it seems to work perfectly with this change :) Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2010, 4:49 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
great debug!

(actually is human bug in 'translation' for post upload. In original used simulated object function in place of global vars, but seemed to complex so 'simplified' for posting...)

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, Bing [Bot], rbrtryn, Yahoo [Bot] and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group