Click here to Skip to main content
15,569,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I know DDE is old fashion outdated technology. But I am creating a C# Windows Form application to send data to Excel file for research purpose. I use Win32 DDE functions and below is what I have tried so far.

What I have tried:

[DllImport("user32.dll", EntryPoint = "DdeInitialize")]
public static extern int DdeInitialize(out uint pidInst, IntPtr pfnCallback, IntPtr afCmd, IntPtr ulRes);

[DllImport("user32.dll", EntryPoint = "DdeConnect")]
private static extern IntPtr DdeConnect(uint idInst, IntPtr hszService, IntPtr hszTopic, IntPtr pCC);

[DllImport("user32.dll", EntryPoint = "DdeCreateStringHandle")]
private static extern IntPtr DdeCreateStringHandle(uint idInst, string psz, int iCodePage);

public Form1()
{
    InitializeComponent();
    Process application = new Process();
    application.StartInfo.FileName = @"C:\Users\xxx\Desktop\DDE_Client.xlsx";
    application.Start();
    uint instId;
    DdeInitialize(out instId, application.MainWindowHandle, IntPtr.Zero, IntPtr.Zero);

    IntPtr sPtr = DdeCreateStringHandle(instId, "Excel", 1004);
    IntPtr tPtr = DdeCreateStringHandle(instId, "Sheet1", 1004);

    IntPtr channel = DdeConnect(instId, sPtr, tPtr, (IntPtr)null);
}


DdeConnect returns non-zero value which indicates the connection is successful.

My question:

How to send a string value to the excel sheet? For example, I want to send "Name" to excel cell A1. Which DDE function should I use for the task?
Posted
Updated 11-Aug-18 12:50pm

1 solution

 
Share this answer
 
Comments
Dilan Shaminda 11-Aug-18 18:19pm    
I saw this post. But I couldnt find out DDESend function in the DDEML function list.
https://docs.microsoft.com/en-us/windows/desktop/dataxchg/dynamic-data-exchange-management-library-functions

I think that functions is specific to the MS Access application.
Gerry Schmitz 11-Aug-18 20:26pm    
Looks like you need the "notifications" (Execute and Poke):

https://docs.microsoft.com/en-us/windows/desktop/dataxchg/dynamic-data-exchange-notifications

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900