Solved

DDE/PostMessage

Posted on 1998-01-05
4
1,011 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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