DDE advice loop 
Author Message
 DDE advice loop

I used this code to make a dll. I use this dll from a java apps.

This code works for a DDE request. I would like it to make an advice
loop.
What should I change?
I know I should change XTYP_REQUEST by XTYP_ADVSTART
but what else?
I am a beginner in C++.

#include <stdio.h>
#include <jni.h>
#include "server_dde_CDDE.h"
#include "Request.h"

struct MyDDE{
 char    m_ReceivedData[MAX_STRING_SIZE];        // Used to store data
received via DDE
 HCONV   m_HConv;                                // handle to a DDE
Cnversation
 HSZ     m_Service;                              // handle of service
name str
 HSZ     m_Topic;                                // handle of topic name
str
 HSZ     m_Item;                                 // handle of item name
str
 DWORD   m_InstId;                               // DDE Instance Handle

Quote:
};

HDDEDATA WINAPI CallBack(WORD type, WORD w, HCONV hConv,HSZ h1, HSZ h2,
HDDEDATA hData, DWORD w2, DWORD w3)
{

  switch (type) {
 case XTYP_ADVDATA:
  //if (hConv == m_HConv)
  // ReceivedData(hData);

      return (HDDEDATA)DDE_FACK;

 case XTYP_XACT_COMPLETE:
  //if (hConv == m_HConv)
  // ReceivedData(hData);
      break;

 case XTYP_DISCONNECT:
  //m_HConv = 0;
  break;

 case XTYP_ERROR:
  break;
  }
  return 0;

Quote:
}

// for calling this dll from java
JNIEXPORT jstring JNICALL
Java_server_dde_CDDE_getItem
(JNIEnv *env, jobject obj, jstring server, jstring topic, jstring item)
{

  const char *svr = (*env)->GetStringUTFChars(env, server, 0);
  const char *top = (*env)->GetStringUTFChars(env, topic, 0);
  const char *it = (*env)->GetStringUTFChars(env, item, 0);
  struct MyDDE client;
  struct MyDDE* pclient;
  pclient = &client;
 connectDDE(pclient, svr, top, it);
 sendCommande(pclient);
 disconnectDDE(pclient);
 //printf("%s.\n",pclient->m_ReceivedData);
  //printf("%s", svr);
  //scanf("%s", buf);
  (*env)->ReleaseStringUTFChars(env, server, svr);
  (*env)->ReleaseStringUTFChars(env, topic, top);
  (*env)->ReleaseStringUTFChars(env, item, it);
  return (*env)->NewStringUTF(env, pclient->m_ReceivedData);

Quote:
}

void connectDDE(struct MyDDE* client, const char * serv, const char *
topi, const char * ite){
 client->m_InstId = 0;
 if (DdeInitialize(&(client->m_InstId), (PFNCALLBACK)(FARPROC)CallBack,
APPCMD_CLIENTONLY, 0) != DMLERR_NO_ERROR) {
  return;
 }

 //-----------------------------------------------------------------------

 // Initialize Data members and the ddeClient so that the window proc
can
 // see it.  Then, create DDE string handles, checking validity.
 //------------------------------------------------------------------------

 client->m_ReceivedData[0] = 0;
    client->m_Service = client->m_Topic = client->m_Item = 0;

    client->m_Service = DdeCreateStringHandle(client->m_InstId, serv,
CP_WINANSI);
 client->m_Topic = DdeCreateStringHandle(client->m_InstId, topi,
CP_WINANSI);
 client->m_Item = DdeCreateStringHandle(client->m_InstId, ite,
CP_WINANSI);
 if (!client->m_Service || !client->m_Topic || !client->m_Item) {
  return;
 }

 //------------------------------------------------------------------------

 // Establish DDE link    If the connection cannot be
 // established, exit.  Once the connection is established, you have the

 // ability to execute macro strings or make macro based requests.
 //------------------------------------------------------------------------

 client->m_HConv = DdeConnect(client->m_InstId, client->m_Service,
client->m_Topic, (PCONVCONTEXT) NULL);

Quote:
}

void disconnectDDE(struct MyDDE* client){
 if (client->m_HConv){
  DdeDisconnect(client->m_HConv);     // Let the other party know we are
leaving
  DdeFreeStringHandle(client->m_InstId, client->m_Service);
  DdeFreeStringHandle(client->m_InstId, client->m_Topic);
  DdeFreeStringHandle(client->m_InstId, client->m_Item);
 }
 if (client->m_InstId) {
  DdeUninitialize(client->m_InstId);
 }

Quote:
}

void sendCommande(struct MyDDE* client) {
 HDDEDATA x;
   UINT lerror;

//------------------------------------------------------------------------

   // In this second sections, we will request data from GroupWise by
   // sending a macro command to request data.  Once again, simply alter

   // m_string attribute to send different requests.

//------------------------------------------------------------------------

   //  Sending the DDE Command
 x = DdeClientTransaction(  0, 0, client->m_HConv, client->m_Item,
CF_TEXT, XTYP_REQUEST, 2000, 0);
   // Check the error code
 lerror = DdeGetLastError(client->m_InstId);

 if (x != NULL){
  DdeGetData(x, (LPBYTE)(client->m_ReceivedData), 256L, 0L);
  printf("%s.\t",client->m_ReceivedData);
 }
 DdeFreeDataHandle(x);

Quote:
}

--
Loubet Serge

http://www.*-*-*.com/
http://www.*-*-*.com/


Fri, 28 Jun 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. For loops into for loops

2. Loop or Loops in "C"

3. (Newbie) My Loop Isn't Looping - Aargh!

4. SEMA - WHILE loop in a FOR loop !

5. For loops into for loops

6. wanted - C and/or Fortran source for 24-loop Livermore Loops

7. requesting data from DDE Server

8. DDE with C# ?

9. how to drive word or excel with dde ?

10. DDE

11. DDE and C#

12. DDE Client

 

 
Powered by phpBB® Forum Software