logo

DDE / DdeQueryNextServer

manfred_kiene posted on Friday, July 13, 2007 2:59 AM

Hello,

I have to make a DDE-Connection from dot.net (as a Client).
The DDE-Implementation from Brian Gideon (http://www.ozemail.com.au/
~markhurd/vbnetdde.zip)
works, but I still need a function to list all avaiable DDE-
applications.

I found this example in C:
http://msdn2.microsoft.com/en-us/library/ms997517.aspx
Sourcecode:
www.microsoft.com/downloads/details.aspx?familyid=F89F86DF-04D7-4464-AB21-9EB1679F41BD&displaylang=en

Who can help me to migrate the "list of DDE-Applications" to C#
(see DdeConnectList and DdeQueryNextServer)

Manfred Kiener

DDE / DdeQueryNextServer

Brian Gideon posted on Wednesday, July 25, 2007 8:14 PM

Actually, that one is not mine.  I moved mine from the gotdotnet site
to http://www.codeplex.com/ndde recently.



Mine doesn't either really.  It does have an API that raises an event
when a new server registers using the DDEML, but that's it.  Well,
then there's the DdeMonitor class which monitors all activity on a
system, but honestly, I can't remember what all it can monitor.  DDE
is nearly dead so I don't really support the library anymore.  In
fact, it's been almost 2 years since I did anything with it.


I have a lot of experience using DDE in C# so I could help if you have
specific questions, but I really recommend moving away from the
technology altogether.

DDE / DdeQueryNextServer

Mark Hurd posted on Friday, July 27, 2007 7:54 PM

A C# DDEML solution would be better for you, but my sample above already
enumerates all available DDE applications because if follows the basic
DDE protocol when initiating a connection: It broadcasts to all windows
a request to respond to DDE. You could accumulate the responses and not
(necessarily) start a connection.

Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)

Thank you for your answers.

manfred_kiene posted on Tuesday, July 31, 2007 5:33 PM

Thank you for your answers.

I know that DDE is a dead tecnology, but in my case I have no chance
to change the technology.

I googled a lot about DDE and I am a little bit confused:
What exact is DDEML?

Is DDEML to use e.g.

[DllImport("user32.dll", EntryPoint="DdeInitialize",
CharSet=CharSet.Ansi)]
public static extern int DdeInitialize(ref int pidInst,
DdeCallback pfnCallback, int afCmd, int ulRes);

This was my understanding from DDEML, but Mark says:

Marks sample is very complex and uses "DdeInitialize" too, is there an
easier way to be an DDE-Client?

@Mark:

I adapted the sample to be a DDE-Client for a barcode tool from will-
software
(www.will-software.com) and it works very fine (to be a DDE-Client for
this barcode-Software is ONLY A SAMPLE,
I need DDE to simulate a 15 years old technoligie which can control
DDE-Servers in many cases).
I tried to debug your sample, but I didn't find what you mean.
Could you give me more hints (e.g. a methode-name where the broadcast
is realized?)

@Brian:
Yes, I have a specific question.
But the sample is difficult to isolate to print the sourcecode here.

I call DdeConnectList (from user32.dll) and get a integer-Handle for a
list of DDE-Application (I belive!).
With DdeQueryNextServer I get exact the same number of int-handles (in
my case I got 4 int-handles), as the c++ - Tool.
(Folders, PROGMAN, Shell, Winword)
But I can not resolve the int-handles e.g. to the application-Name
(DdeQueryString), may be there ist only a little mistake with the call
and interop.

Maybe if you could spent 10 minutes of your time you will find the
error.
In this case I would send you the complete Sample-solution (just a few
KB)

Thank you and regards,

Manfred Kiener

DDE / DdeQueryNextServer

Brian Gideon posted on Friday, August 03, 2007 4:44 PM

Dynamic Data Exchange Management Library.  It encapsulates a lot of
the complexities of passing messages back and forth between
applications.


Yes, DdeInitialize is part of the DDEML.


I didn't see the call in his example, but then again I didn't look
very closely.  He's probably mixing the DDEML with the raw DDE message
protocol which, as I understand, should be perfectly acceptable.

As far as creating a DDE client easily...have you looked at the
library I provide?  To request data from a server the code would look
like the following.

DdeClient client = new DdeClient("myserver", "mytopic");
client.Connect();
string data = client.Request("myitem", 60000);

It can't get much easier than that.


You talk about controlling a server...that's usually done by doing a
DDE execute.  The library I provide supports that easily as well with
the DdeClient.Execute method.


DdeConnectList and DdeQueryNextServer are a little complicated to
use.  I'm still unclear as to why you want to use them.  Can you
clarify?

DDE / DdeQueryNextServer

manfred_kiene posted on Sunday, August 05, 2007 5:18 AM

Hello,


Brian: yes, you are right. At my first message I talked about your
NDDE but
write the linkt to Marc's sample. Sorry
I realized that yesterday.

This solution to get "a list of DDE-Servers" works
(in context with the NDDE-library)


I Changed this definitions in DDEML.CS:

public static extern IntPtr DdeConnectList(int idInst, IntPtr
hszService, IntPtr hszTopic, IntPtr hConvList, ref
NDde.Foundation.Ddeml.CONVCONTEXT pCC/*IntPtr pCC*/);
public static extern int DdeQueryConvInfo(IntPtr hConv, int
idTransaction, ref CONVINFO pConvInfo/*IntPtr pConvInfo*/);


I added this in DDEMLClient.cs
public string[] GetListOfDdeServer()
{
ArrayList DdeServers = new ArrayList();
IntPtr hszSystem =
Ddeml.DdeCreateStringHandle(_InstanceId,"System",Ddeml.CP_WINANSI);

NDde.Foundation.Ddeml.CONVCONTEXT pCC = new
NDde.Foundation.Ddeml.CONVCONTEXT();
pCC.cb = (ushort)Marshal.SizeOf(pCC);
IntPtr hConvList =
Ddeml.DdeConnectList(_InstanceId,IntPtr.Zero,hszSystem,
IntPtr.Zero, // new list
ref pCC); // default context
Ddeml.DdeFreeStringHandle(_InstanceId,hszSystem);
//
// Walk the list adding the server names to our listbox
//
IntPtr hConv = IntPtr.Zero;

Ddeml.CONVINFO pConvInfo = new Ddeml.CONVINFO();
pConvInfo.cb = (ushort)Marshal.SizeOf(pConvInfo);

while((hConv = Ddeml.DdeQueryNextServer(hConvList,hConv)) !
= IntPtr.Zero)
{
int ui =
Ddeml.DdeQueryConvInfo(hConv,Ddeml.QID_SYNC,ref pConvInfo);

StringBuilder psz = new StringBuilder(255);
Ddeml.DdeQueryString(_InstanceId,
(IntPtr)pConvInfo.hszSvcPartner,psz,psz.Capacity,Ddeml.CP_WINANSI);

DdeServers.Add(psz.ToString());
Debug.WriteLine(psz.ToString());
}
//
// Free the list handle
//
Ddeml.DdeDisconnectList(hConvList);

return (string[])DdeServers.ToArray(typeof(string));
}

It was i little "try and error" (e.g. Thread-Handling), but now it
works "good enought"

@Brian, @Marc:
thank you for your help.

regards
Manfred Kiener

DDE / DdeQueryNextServer

Brian Gideon posted on Monday, August 06, 2007 3:15 PM

Thanks Manfred.  If DDE were not already nearly defunct and if I
actually had the motivation to keep supporting NDde I'd probably add
that method and publish a new release :)

DDE / DdeQueryNextServer

greenmelon200 posted on Thursday, September 13, 2007 12:21 PM

Hi, Manfred,

I am sorry to bother you, but I found the following thread online, and
I am having issues similar to yours:

http://groups.google.com/group/microsoft.public.dotnet.framework.interop/browse_thread/thread/d6c9031c0aafa0d5/aa9f445e0718167f#aa9f445e0718167f

, and I see that you have added a very useful function (to the great
NDDE library) that is supposed to list all the available DDE server
names.

I have 2 questions, if you don't mind:

1) How do you properly call this function?  (examples?)
2) How can you connect to two different DDE servers which provide the
same DDE server name? I basically start two apps that both provide the
same DDE Server names, and I can't distinguish between them with the
regular DDEClient, but I want to connect to both of them. :(

Thank you!

Hello,1) It is a litte bit tricky because of multithreading.

manfred_kiene posted on Tuesday, September 25, 2007 3:42 PM

Hello,

1) It is a litte bit tricky because of multithreading. Please email me
you still need help
2) I am not shure if it is possible to connect to two applications
with the same name.

Manfred Kiener

How to create a DDE connection from within a WPF application

Peter Kovach posted on Tuesday, November 04, 2008 12:38 PM

I need to create and use a DDE from within my WPF app, because I need to get and send data to an older simulator (a VisSim simulation).  VisSim supports creating a bi-directional DDE connection



What is the best way to do this?



Thanks!

Peter


Didn't Find The Answer You Were Looking For?

EggHeadCafe has experts online right now that may know the answer to your question.  We pay them a bonus for answering as many questions as they can.  So, why not help them and yourself by becoming a member (free) and ask them your question right now?
Create Account & Ask Question In Live Forum





Pete's Resume  |  Robbe's Resume  |  Neado  |  Free Icons  |  Privacy  |   (c) 2010