Solved

DDE/PostMessage

Posted on 1998-01-05
4
996 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now