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

x
?
Solved

DDE - getting started.

Posted on 1999-07-09
8
Medium Priority
?
206 Views
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.
0
Comment
Question by:Malek103197
[X]
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
8 Comments
 

Author Comment

by:Malek103197
ID: 1309443
Edited text of question.
0
 
LVL 3

Accepted Solution

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

class CDDEApp : public CWinApp
{
public:
      DWORD pidInst;
      CDDEApp();

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CDDEApp)
      public:
      virtual BOOL InitInstance();
      virtual int ExitInstance();
      //}}AFX_VIRTUAL

// Implementation

      //{{AFX_MSG(CDDEApp)
            // NOTE - the ClassWizard will add and remove member functions here.
            //    DO NOT EDIT what you see in these blocks of generated code !
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

BOOL CDDEApp::InitInstance()
{
      AfxEnableControlContainer();
      DdeInitialize(&pidInst,NULL,APPCMD_CLIENTONLY,0);
      // 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
#else
      Enable3dControlsStatic();      // Call this when linking to MFC statically
#endif

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

            HCONV hConv = DdeConnect(pidInst,hService,0,NULL);
            if(hConv == NULL)
            {
                  AfxMessageBox("Could Not Connect");
                  return FALSE;
            }
            DdeFreeStringHandle(pidInst,hService);
            CString cmd = "[CreateGroup(" + dlg.m_strGroup+ ")]";
            LPCTSTR data = (LPCTSTR)cmd;
            DWORD pdwResult;
            DdeClientTransaction((LPBYTE)data,cmd.GetLength(),hConv,
                  NULL,0,XTYP_EXECUTE,5000,&pdwResult);

            cmd = "[ShowGroup(" + dlg.m_strGroup+ ")]";
            data = (LPCTSTR)cmd;
            
            DdeClientTransaction((LPBYTE)data,cmd.GetLength(),hConv,
                  NULL,0,XTYP_EXECUTE,5000,&pdwResult);

            cmd = "[AddItem(" + dlg.m_strFile + "," + dlg.m_strItem+ ")]";
            data = (LPCTSTR)cmd;
            
            DdeClientTransaction((LPBYTE)data,cmd.GetLength(),hConv,
                  NULL,0,XTYP_EXECUTE,5000,&pdwResult);

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

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

Expert Comment

by:chensu
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

http://msdn.microsoft.com/library/sdkdoc/winbase/ddemlib_743d.htm

And there are a lot of technical articles about DDE in the MSDN Library. Go to MSDN Online Library (http://msdn.microsoft.com/library/), see the Technical Articles\Windows Platform\Base Services\DDE

You can also search Microsoft KB article for Excel AND DDE at http://search.microsoft.com/us/dev/.

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
http://www.microsoft.com/officedev/tips/autovc.htm

Office Automation with MFC
http://support.microsoft.com/support/officedev/mfckb.asp
0
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

by:mrmzxwfl
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.



0
 

Author Comment

by:Malek103197
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:
DdeInitialize(&pidInst,NULL,APPCMD_CLIENTONLY,0);

thanks
0
 

Author Comment

by:Malek103197
ID: 1309448
For VCGuru,

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

Author Comment

by:Malek103197
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?
0
 

Author Comment

by:Malek103197
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?

Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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