Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


DDE - getting started.

Posted on 1999-07-09
Medium Priority
Last Modified: 2013-11-20
I'm trying to get started on writing some DEE apps but have not found much doc. on this topic in VC++. Can someone give me some sample code to get started, say to communicate with excel and pass some variables to and from excel from my app. I'm not sure how many points this would be worth as I do not know the complexity of such a task in VC++, so I'll start off low at 50.
Question by:Malek103197
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 1309443
Edited text of question.

Accepted Solution

VCGuru earned 150 total points
ID: 1309444
Hi Malek,
Check out for functions beginning with DDE. Hope this is helpful

class CDDEApp : public CWinApp
      DWORD pidInst;

// Overrides
      // ClassWizard generated virtual function overrides
      virtual BOOL InitInstance();
      virtual int ExitInstance();

// Implementation

            // NOTE - the ClassWizard will add and remove member functions here.
            //    DO NOT EDIT what you see in these blocks of generated code !

BOOL CDDEApp::InitInstance()
      // Standard initialization
      // If you are not using these features and wish to reduce the size
      //  of your final executable, you should remove from the following
      //  the specific initialization routines you do not need.

#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
      Enable3dControlsStatic();      // Call this when linking to MFC statically

      CDDEDlg dlg;
      m_pMainWnd = &dlg;
      int nResponse = dlg.DoModal();
      if (nResponse == IDOK)
            HSZ hService = DdeCreateStringHandle(pidInst,

            HCONV hConv = DdeConnect(pidInst,hService,0,NULL);
            if(hConv == NULL)
                  AfxMessageBox("Could Not Connect");
                  return FALSE;
            CString cmd = "[CreateGroup(" + dlg.m_strGroup+ ")]";
            LPCTSTR data = (LPCTSTR)cmd;
            DWORD pdwResult;

            cmd = "[ShowGroup(" + dlg.m_strGroup+ ")]";
            data = (LPCTSTR)cmd;

            cmd = "[AddItem(" + dlg.m_strFile + "," + dlg.m_strItem+ ")]";
            data = (LPCTSTR)cmd;

      else if (nResponse == IDCANCEL)
            // TODO: Place code here to handle when the dialog is
            //  dismissed with Cancel
            if(InitiateSystemShutdown("SHRIDHAR","I am Shutting Down",10,FALSE,TRUE) == 0)

      // Since the dialog has been closed, return FALSE so that we exit the
      //  application, rather than start the application's message pump.
      return FALSE;
LVL 23

Expert Comment

ID: 1309445
To communicate with Excel, DDE is not recommended. You should use Automation instead. Anyway, DDEML documentation is in the Platform SDK. See online version at

And there are a lot of technical articles about DDE in the MSDN Library. Go to MSDN Online Library (, see the Technical Articles\Windows Platform\Base Services\DDE

You can also search Microsoft KB article for Excel AND DDE at

If you want to do Automation, check out the Compiler COM Support samples that come with Visual C++. And

Automating Office with VC++: Knowledge Base Articles

Office Automation with MFC
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1309446
Make a new class.It can base on MFC or not.
In the new class, you can proceeding DDE routine.
I have done this before.


Author Comment

ID: 1309447
For VCGuru:

Sorry for not getting back to you sooner. I've tried implementing the code you provided and have been reading up on the DDEML, however, I did not make it to first base. I placed the following function you provided in the InitInstance and got an "Unrecognized command", do I need to place a specific #include statement ?

Did not recognize this function:


Author Comment

ID: 1309448
For VCGuru,

Ignore that last comment, I discovered I needed to #include "Ddeml.h"

Author Comment

ID: 1309449
For VCGuru,

Thanks for the help. One thing I find difficult is translating the interactive commandsm, say in progman, to instructional commands from my VC++ code (eg. AddItem(C:/WINDOWS/CALC.EXE, Calculator)) how do i know to pass 2 variables and how would i know to pass the working directory and the Name?

Author Comment

ID: 1309450
For VCGuru,
A basic question. I have a dialog based app. called MyProg. I wish to pop up a MessageBox in a the InitInstance of MyProgApp. I've tried using the AfxMessageBox("Connction Failed"); but it does not get launched. Any ideas?


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question