Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-04-2009
Member
 
Join Date: Feb 2009
Posts: 117
Use DDE to retrieve values

Hello to all.
I would like to communicate with an application using DDE. I tried with Excel by entering a formula "= app | topic_ Name" and it works very well.

I tried under Visual C + + express but I have not succeeded.

Code:
char * szApplication = "app";  
      char * szTopic = "TOPIC";  
      ATOM atomApplication = * szApplication == 0?  
		  NULL: GlobalAddAtom (szApplication);  
	  ATOM atomTopic = * szTopic == 0?  
		  NULL: GlobalAddAtom (szTopic);  

	  printf ( "Sending message ... \ n"); 
	  SendMessage (HWND_BROADCAST, 
		  WM_DDE_INITIATE, 
		  (WParam) NULL, 
		  MAKELONG (atomApplication, atomTopic)); 

	  printf ( "message sent \ n"); 

      if (atomApplication! = NULL)  
          GlobalDeleteAtom (atomApplication);  
      if (atomTopic! = NULL)  
          GlobalDeleteAtom (atomTopic); 


	  printf ( "Waiting for a message \ n"); 
	  MSG message; 
	  GetMessage (& message, 
		  NULL, 
		  0, 
		  0); 
          printf ( "Message received \ n");
Sending the message seems to be OK but I do not get any response.
If someone sees an error in my program or an example (simple) to use DDE in C it would be nice.

Thank you
Reply With Quote
  #2  
Old 06-04-2009
Member
 
Join Date: Apr 2008
Posts: 193
Re: Use DDE to retrieve values

This is normal you do not loop until the message!
You call the getMessage but he spends it on something else!
If the DDE link in Excel takes a few ms and more you will receive nothing
So the basic solution is to make a timer, and looping over getMessage with a timeout value
Something more sophisticated would be a thread

Looking at the MSDN help on getMessage.

Quote:
GetMessage Function


The getMessage function retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval.

Unlike getMessage, the PeekMessage function does not wait for a message to be posted before returning.


An application typically uses the return value to determine whether to end the main message loop and exit the program.
Reply With Quote
  #3  
Old 06-04-2009
Member
 
Join Date: Feb 2009
Posts: 117
Re: Use DDE to retrieve values

Quote:
You call the getMessage but he spends it on something else!
Thank you for your answer but getMessage is blocking:

Quote:
Unlike getMessage, the PeekMessage function does not wait for a message to be posted before returning.
In fact, I put a printf after getMessage and the program gets stuck on getMessage, therefore I do not get any message.
Reply With Quote
  #4  
Old 06-04-2009
Member
 
Join Date: Mar 2008
Posts: 258
Re: Use DDE to retrieve values

Hi this prehistoric DDE is better to use COM, you can create a link OLE Automation / COM Excel to read / write to an Excel file
Otherwise I think it works better in the loop of messages from the application process messages DDE.

What type of project? win32 console UI?
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Use DDE to retrieve values"
Thread Thread Starter Forum Replies Last Post
How to assign and retrieve values from JTextField in java swing Rao's Software Development 4 20-01-2012 11:56 AM
W32 registry values are not getting matched by the default values Angrzej Networking & Security 5 19-05-2011 12:23 PM
Retrieve multiple values from java class Ash maker Software Development 5 13-02-2010 12:05 AM
What are the RGB values? Renderman21 Operating Systems 3 21-11-2009 09:45 AM
How to use enum values in VB $tatic Software Development 1 10-08-2009 06:25 PM


All times are GMT +5.5. The time now is 12:50 AM.