• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 555
  • Last Modified:

boost for my simple DDE application

Hi !
I want to build an app. which will monitor my IE and NetScape using DDE Services. But I don't know how to start that as I am a novice to DDE. Thus, I want some code for the client DDE which can connect to NETSCAPE and IE. and whenever a user goes to a web site, my app. can display that uRL in a messagebox. I am already lost in the wilderness of MSDN. So, please help me with some code sample.

I had written a small dialog based  app. to act as a DDE client, but it's not working the correct way.....    :-(

These are the things I had implemented :

the constructor of app. lok likes :

extern DWORD dwidInst;   //Global variable

      // Initialization of dde application.
      if(DdeInitialize(&dwidInst, LocationDdeCallBack, APPCLASS_MONITOR|MF_POSTMSGS|MF_CONV|MF_CALLBACKS, 0ul)){
            dwidInst = 0UL;

then in the OnInitDialog() of my dialog class, I had written the following code :

int OnInitDialog()

      HCONV hConv = NULL;
      CString csItem = "";
      CString csTemp = "";

      if(dwidInst == 0UL){
                  MessageBox(NULL,"Dde Initialization Failed...","Error", MB_OK);
      //Connect to the Netscape server.
      HSZ hszService = DdeCreateStringHandle(dwidInst, "NETSCAPE", CP_WINANSI);
      hConv = DdeConnect(dwidInst, hszService,0L, NULL);
      // Check for the connection
      if(hConv == 0UL){
            char *sTemp = "Unable to start convertion with NETSCAPE...";
            MessageBox(NULL,sTemp, "Error", MB_OK);

      CString csItem;

      //This seems to be a bottlenect. Please guide me how can I decide the correct values for csItem

      HSZ hszItem = DdeCreateStringHandle(dwidInst, csItem, CP_WINANSI);
      HDDEDATA hRetVal = DdeClientTransaction(NULL, 0ul, hConv, hszItem, CF_TEXT, XTYP_ADVSTART, 5000L, NULL);
      //UINT k=DdeGetLastError(dwidInst);
      //The hRetValue always comes out to be 0 ?????
      //The value of k tells INVALID PARAMETER

//My Call back functions looks like this:
//Just to know which all messages i am receiving

HDDEDATA CALLBACK LocationDdeCallBack(UINT type, UINT fmt,
      HCONV hconv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1,
      DWORD dwData2)      {
      CNetObj cn;

      CString c2 = cn.GetString(hsz1);
      if(!c2.IsEmpty())      AfxMessageBox(c2);

      case      XTYPF_NOBLOCK:
      case      XTYPF_NODATA:
      case      XTYPF_ACKREQ:
      case      XCLASS_MASK:
      case      XCLASS_BOOL:  
      case      XCLASS_DATA:
            AfxMessageBox("XCLASS_DATA ");
      case      XCLASS_FLAGS:    
            AfxMessageBox("XCLASS_FLAGS ");
      case      XCLASS_NOTIFICATION:
            AfxMessageBox("XCLASS_NOTIFICATION ");
      case      XTYP_ERROR:
            AfxMessageBox("XTYP_ERROR ");
      case      XTYP_ADVDATA:
            AfxMessageBox("XTYP_ADVDATA ");
      case      XTYP_ADVREQ:
            AfxMessageBox(" XTYP_ADVREQ");
      case      XTYP_ADVSTART:
            AfxMessageBox("XTYP_ADVSTART ");
      case      XTYP_ADVSTOP:
            AfxMessageBox(" XTYP_ADVSTOP");
      case      XTYP_EXECUTE:
            AfxMessageBox("XTYP_EXECUTE ");
      case      XTYP_XACT_COMPLETE:
            AfxMessageBox("XTYP_XACT_COMPLETE ");
      case      XTYP_REGISTER:
            AfxMessageBox("XTYP_REGISTER ");
      case      XTYP_UNREGISTER:
            AfxMessageBox("XTYP_UNREGISTER ");
      case XTYP_CONNECT :
            AfxMessageBox("XTYP_CONNECT ");
            AfxMessageBox("XTYP_CONNECTCONFIRM ");
      case XTYP_DISCONNECT :
            AfxMessageBox("XTYP_DISCONNECT ");
      case XTYP_POKE :
            AfxMessageBox("XTYP_POKE ");
      case XTYP_REQUEST :
      return (HDDEDATA) NULL;

Right now when i run this application i only get XTYP_REGISTER message when i starts netscape,
and XTYP_UNREGISTER when i closes the netscape browser
and nothing else

I am a novice to DDE programming and MSDN samples are too bulky for me...
 so please guide me and tell me what's wrong with the code

I just want to receive all the URL addresses that the user is visiting.

  • 5
  • 4
1 Solution
Your parameter to XTYP_ADVSTART is wrong.  It needs to specify the topic that you are interested in, instead of just "0".

But I think that you should really try looking at: http://developer.netscape.com/docs/manuals/communicator/DDE/abtdde.htm

and, more specifically:

Which, I think, is closer to what you really want to do.

(IE uses a similar enough DDE interface, so your code should be able to run off of both.  Your milage may vary.... ;)
sun307Author Commented:
thanx abesoft!
I had tried that but couldn't figure out the correct parameter. the netscape document for www_registerurlecho just has the following lines and it's dificult to make out the parameter from there :
Netscape is: Server.

Transaction Type: XTYP_POKE.

Item (Arguments): qcsServer
qcsServer is the DDE server that wishes to receive WWW_URLEcho topics.

Description: This topic registers qcsServer to be notified when the loading of a URL occurs, via the WWW_URLEcho topic. Multiple servers can be registered with this topic. None are denied registration. The SDI draft at the time this document was written indicates the transaction type as XTYP_REQUEST, which is a possible incompatibility.
sun307Author Commented:
This question has a deletion request Pending
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

This question no longer is pending deletion

HSZ hszItem = DdeCreateStringHandle(dwidInst, csItem, CP_WINANSI);
// register your server name
DdeNameService( dwidInst, csItem, 0, DNS_REGISTER);
// Ask NS to send URL's to that server.
HDDEDATA hRetVal = DdeClientTransaction(NULL, 0ul, hConv, hszItem, CF_TEXT, XTYP_REQUEST, 5000L, NULL);
// Or maybe XTYP_POKE?

For "myServerName", you should substitute the name of your DDE server.  You will also need to call DdeNameService to unregister your server name before termination.
sun307Author Commented:
Hi abesoft!
can u clarify one more point....
does the same application can work for IE too ....????
I did this unser IE and Netscape about five years ago, and the same thing worked for both of them.  (There may have been differences, but they were minor.  The service names were different, obviously.)

Oh, by the way, I didn't compile or test the code snippet that I gave you, so you may need to massage it to get it to fit.  Good Luck!
sun307Author Commented:
Answer accepted
sun307Author Commented:
Thanx and I am sorry for accepting ur answer so late
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now