Any DDE server success stories?

D

Dennis Myrén

Hi.

A recent thread at dotnet.general brought me back to DDE(Dynamic Data
Exchange) Interfaces.

I was trying to use the DDE API functions defined in user32.dll
to connect to and to control a DDE server(in this case, the server was
Acrobat).

I manage to initialize DDE using DdeInitializeA
and i also manage to connect to the DDE server using DdeConnect.

Then, after creating a DDE command(which i know is correct),
and creating a data handle for that command(DdeCreateStringHandleA,
DdeCreateDataHandle),
i try to use DdeClientTransaction to execute the command.

I get no error messages whatsoever, however, nothing happens!
The commands i have fed to the DDE server was obviously not executed.

Has anyone successfully connected to and controlled a DDE server
using C# and the Windows API?

Please share your experience.

You might ask yourself why on earth i want to use DDE in 2004,
but there is no other way(COM way) to do what i want to do, and i think
it is somewhat funny for a change as well.
 
B

Brian Gideon

Dennis,

You do not create a data handle when sending a DDE command. Instead,
just convert the string containing the command you want to send into a
byte array and pass that into the DdeClientTransaction API. Here is an
example.

[DllImport(
"user32.dll",
EntryPoint="DdeClientTransaction",
CharSet=CharSet.Ansi)]
public static extern IntPtr DdeClientTransaction(
byte[] pData,
uint cbData,
IntPtr hConv,
IntPtr hszItem,
uint wFmt,
uint wType,
uint dwTimeout,
ref uint pdwResult);

public void Execute(string command) {

// Call DdeInitialize and DdeConnect before executing
// the following code.

byte[] data = Encoding.ASCII.GetBytes(command + "\x00");

uint timeout = 60000; // 60 seconds
uint returnFlags = 0;
IntPtr result = DdeClientTransaction(
data,
(uint)data.Length,
conversationHandle,
IntPtr.Zero,
CF_TEXT,
XTYP_EXECUTE,
timeout,
ref returnFlags);

if (result == IntPtr.Zero)
{
// There was a failure sending the command.
}
}
 
B

Brian Gideon

Dennis,

You do not create a data handle when sending a DDE command. Instead,
just convert the string containing the command you want to send into a
byte array and pass that into the DdeClientTransaction API. Here is an
example.

[DllImport(
"user32.dll",
EntryPoint="DdeClientTransaction",
CharSet=CharSet.Ansi)]
public static extern IntPtr DdeClientTransaction(
byte[] pData,
uint cbData,
IntPtr hConv,
IntPtr hszItem,
uint wFmt,
uint wType,
uint dwTimeout,
ref uint pdwResult);

public void Execute(string command) {

// Call DdeInitialize and DdeConnect before executing
// the following code.

byte[] data = Encoding.ASCII.GetBytes(command + "\x00");

uint timeout = 60000; // 60 seconds
uint returnFlags = 0;
IntPtr result = DdeClientTransaction(
data,
(uint)data.Length,
conversationHandle,
IntPtr.Zero,
CF_TEXT,
XTYP_EXECUTE,
timeout,
ref returnFlags);

if (result == IntPtr.Zero)
{
// There was a failure sending the command.
}
}
 
D

Dennis Myrén

Thank you, Brian!

I will give it a shot.
If you do have C# example codes interacting with a DDE server, i am also
interested
in that.

DDE, long time ago!


--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Dennis,

You do not create a data handle when sending a DDE command. Instead,
just convert the string containing the command you want to send into a
byte array and pass that into the DdeClientTransaction API. Here is an
example.

[DllImport(
"user32.dll",
EntryPoint="DdeClientTransaction",
CharSet=CharSet.Ansi)]
public static extern IntPtr DdeClientTransaction(
byte[] pData,
uint cbData,
IntPtr hConv,
IntPtr hszItem,
uint wFmt,
uint wType,
uint dwTimeout,
ref uint pdwResult);

public void Execute(string command) {

// Call DdeInitialize and DdeConnect before executing
// the following code.

byte[] data = Encoding.ASCII.GetBytes(command + "\x00");

uint timeout = 60000; // 60 seconds
uint returnFlags = 0;
IntPtr result = DdeClientTransaction(
data,
(uint)data.Length,
conversationHandle,
IntPtr.Zero,
CF_TEXT,
XTYP_EXECUTE,
timeout,
ref returnFlags);

if (result == IntPtr.Zero)
{
// There was a failure sending the command.
}
}
 
B

Brian Gideon

Dennis,

I have a example on http://www.gotdotnet.com in the user samples
section. Just search for DDE and you should find it. It's actually a
library that wraps the DDEML. I included examples of how to write your
own DDE client and servers using the library as well.

Brian
 
D

Dennis Myrén

Thanks, Brian.
You have been a great help.
To be honest, i did not think anyone would answer this thread.

I am going to look at your example on gotdotnet.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Dennis,

I have a example on http://www.gotdotnet.com in the user samples
section. Just search for DDE and you should find it. It's actually a
library that wraps the DDEML. I included examples of how to write your
own DDE client and servers using the library as well.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top