Solved

DDE/PostMessage

Posted on 1998-01-05
4
1,015 Views
Last Modified: 2012-08-13
First the sample code:

    char *szApplication="Excel";
    char *szTopic="Sheet1";
    static HWND hwndClientDDE;
    static HWND hwndServerDDE;  
    int atomApplication,atomTopic;
    int atomItem;
    long lgval;
    char *szItemName="R1C1";
    //ADDITIONAL VARIABLES DECLARED HERE...........

lgval=::SendMessage((HWND) -1,     // broadcasts message           WM_DDE_INITIATE,           //initiates conversation       (WPARAM) hwndClientDDE,      //handle of client DDE  
        MAKELONG(atomApplication,  // application-name atom        atomTopic));                //topic-name atom              
 
    //Code to delete atom here................
   
    atomItem = GlobalAddAtom(szItemName);  
   
    lgval=::PostMessage(hwndServerDDE,
            WM_DDE_REQUEST,
            (WPARAM) hwndClientDDE,
            PackDDElParam(WM_DDE_REQUEST, CF_TEXT,             atomItem));

This is pretty much out of MSDN, I am using VC 1.0 (can you believe it!). I want to hook to an Excel spreadsheet. The above SendMessage returns a 1, but then it broadcasts to all active windows so I'm not totally convinced. The PostMessage comes back as 0 and the PackDDElParam is not recognized at all in the compiling(so I tried it with MAKELONG, taking out the WM_DDE_REQUEST - and got the 0). Does anybody know why this doesn't work????
0
Comment
Question by:dpms
  • 2
  • 2
4 Comments
 

Author Comment

by:dpms
ID: 1177530
Edited text of question
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 50 total points
ID: 1177531
The standard form of trying to find the DDE server is to use SendMessage to all top-level windows and asking it if it supports DDE (WM_DDEINITIATE) and if it supports the application with that topic name.

Then any application that supports that DDE conversation will return the HWND of the window you are supposed to communicate with. Then your application will need to use PostMessage to that particular window in order to communicate with it. If the parameters to any of the messages are incorrect, then the client and the server are speaking different languages and won't be to communicate. So you need to use PackDDElParam which is in the header DDE.h. If you don't, then you'll run into problems.


0
 

Author Comment

by:dpms
ID: 1177532
I did put in an " #include <dde.h> " statement from the start. But the packddelparam comes back as unrecognized? Am I missing something?
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1177533
Make sure you have spelled out PackDDElParam correctly and with the right case. The other possibility is that Visual C++ 1.0 may not have the right header file. You may want to search the headers to find out where PackDDElParam may be located.
0

Featured Post

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!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

679 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