示例#1
0
DDEdataHandle::DDEdataHandle(const char *text)
{
    hData = DdeCreateDataHandle(*DDEbase::base, (unsigned char*)text, strlen(text) + 1, 0, NULL, CF_TEXT, 0);
}
示例#2
0
/*
 * RunDDECommand - try to run a Windows specific command
 */
bool RunDDECommand( int token, const char *str, char *tmp1, vi_rc *result, vlist *vl )
{
    vi_rc       rc;
    char        *tmp2;
    char        *tmp3;
    HSZ         hdl;
    HSZ         serverhdl, topichdl;
    DWORD       dword;
    HCONV       hconv;
    HDDEDATA    data;
    char        *ptr;
    int         len;
    jmp_buf     jmpaddr;
    int         jmprc;

    tmp2 = alloca( MAX_INPUT_LINE );
    if( tmp2 == NULL ) {
        return( false );
    }
    tmp3 = alloca( MAX_INPUT_LINE );
    if( tmp3 == NULL ) {
        return( false );
    }

    if( token == T_DDEINIT ) {
        if( !DDEInit() ) {
            *result = ERR_DDE_FAIL;
        } else {
            *result = ERR_NO_ERR;
        }
        return( true );
    }

    if( !UseDDE ) {
        *result = ERR_INVALID_DDE;
        return( true );
    }

    rc = ERR_NO_ERR;
    switch( token ) {
    case T_DDEQUERYSTRING:
        /*
         * syntax: ddequerystring <resvar> handle
         */
        if( !getVarName( &str, tmp1, vl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        str = Expand( tmp3, str, vl );
        if( !GetHSZ( &str, &hdl  ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        len = DdeQueryString( DDEInstId, hdl, NULL, 0, CP_WINANSI ) + 1;
        ptr = MemAlloc( len  );
        DdeQueryString( DDEInstId, hdl, ptr, len, CP_WINANSI );
        VarAddStr( tmp1, ptr, vl );
        MemFree( ptr );
        break;

    case T_DDERET:
        /*
         * syntax: dderet retval
         */
        str = Expand( tmp3, str, vl );
        jmprc = setjmp( jmpaddr );
        if( jmprc == 0 ) {
            StartExprParse( str, jmpaddr );
            DDERet = (HDDEDATA)GetConstExpr();
        } else {
            rc = ERR_INVALID_DDE;
        }
        break;

    case T_DDESERVER:
        /*
         * syntax: ddeserver <serverhandle>
         */
        str = Expand( tmp3, str, vl );
        if( !GetHSZ( &str, &hdl  ) ) {
            rc = ERR_INVALID_DDE;
        } else {
            if( !DdeNameService( DDEInstId, hdl, (HSZ)NULL, DNS_REGISTER ) ) {
                rc = ERR_DDE_FAIL;
            } else {
                ServerCount++;
            }
        }
        break;

    case T_CREATEDDESTRING:
        /*
         * syntax: createddestring <handlevar> "<string>"
         */
        if( !getVarName( &str, tmp1, vl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        if( GetStringWithPossibleQuote( &str, tmp2 ) != ERR_NO_ERR ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        str = Expand( tmp3, tmp2, vl );
        if( !CreateStringHandle( str, &hdl ) ) {
            rc = ERR_DDE_FAIL;
        } else {
            sprintf( tmp2, "%ld", (long)hdl );
            VarAddStr( tmp1, tmp2, vl );
        }
        break;

    case T_DELETEDDESTRING:
        /*
         * syntax: deleteddestring <handle>
         */
        str = Expand( tmp3, str, vl );
        if( !GetHSZ( &str, &hdl ) ) {
            rc = ERR_INVALID_DDE;
        } else {
            DeleteStringHandle( hdl );
        }
        break;

    case T_DDEGETDATA:
        /*
         * syntax: ddegetdata <strvar> <datahandle>
         */
        if( !getVarName( &str, tmp1, vl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        str = Expand( tmp3, str, vl );
        if( !GetHDDEDATA( &str, &data ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        len = DdeGetData( data, NULL, 0, 0 );
        ptr = MemAlloc( len );
        DdeGetData( data, (LPBYTE)ptr, len, 0 );
        VarAddStr( tmp1, ptr,  vl );
        MemFree( ptr );
//      DdeFreeDataHandle( data );
        break;


    case T_DDECREATEDATAHANDLE:
        /*
         * syntax: ddecreatedatahandle <handlevar> <itemhandle> "<string>"
         */
        if( !getVarName( &str, tmp1, vl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        str = Expand( tmp3, str, vl );
        if( !GetHSZ( &str, &hdl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        if( GetStringWithPossibleQuote( &str, tmp2 ) != ERR_NO_ERR ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        data = DdeCreateDataHandle( DDEInstId, (LPBYTE)tmp2, strlen( tmp2 ) + 1,
                                    0, hdl, ClipboardFormat, 0 );
        if( data == (HDDEDATA)NULL ) {
            rc = ERR_DDE_FAIL;
        } else {
            sprintf( tmp2, "%ld", (long)data );
            VarAddStr( tmp1, tmp2, vl );
        }
        break;

    case T_DDECONNECT:
        /*
         * syntax: ddeconnect <convvar> <serverhandle> <topichandle>
         */
        if( !getVarName( &str, tmp1, vl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        str = Expand( tmp3, str, vl );
        if( !GetHSZ( &str, &serverhdl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        if( !GetHSZ( &str, &topichdl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        hconv = DdeConnect( DDEInstId, serverhdl, topichdl, NULL );
        if( hconv == (HCONV)NULL ) {
            rc = ERR_DDE_FAIL;
        } else {
            sprintf( tmp2, "%ld", (long)hconv );
            VarAddStr( tmp1, tmp2, vl );
        }
        break;
    case T_DDEDISCONNECT:
        /*
         * syntax: ddedisconnect <hconv>
         */
        str = Expand( tmp3, str, vl );
        if( !GetHCONV( &str, &hconv ) ) {
            rc = ERR_INVALID_DDE;
        } else {
            DdeDisconnect( hconv );
        }
        break;

    case T_DDEREQUEST:
        /*
         * syntax: dderequest <datavar> <conv> <strhandle>
         */
        if( !getVarName( &str, tmp1, vl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        str = Expand( tmp3, str, vl );
        if( !GetHCONV( &str, &hconv ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        if( !GetHSZ( &str, &hdl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        data = DdeClientTransaction( NULL, 0, hconv, hdl, ClipboardFormat,
                                     XTYP_REQUEST, TIME_OUT, &dword );
        if( data == (HDDEDATA)NULL ) {
            rc = ERR_DDE_FAIL;
        } else {
            len = DdeGetData( data, NULL, 0, 0 ) + 1;
            ptr = MemAlloc( len );
            DdeGetData( data, (LPBYTE)ptr, len, 0 );
            VarAddStr( tmp1, ptr,  vl );
            MemFree( ptr );
            DdeFreeDataHandle( data );
        }
        break;

    case T_DDEPOKE:
        /*
         * syntax: ddepoke "<data>" <conv> <strhandle>
         */
        str = Expand( tmp3, str, vl );
        if( GetStringWithPossibleQuote( &str, tmp1 ) != ERR_NO_ERR ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        if( !GetHCONV( &str, &hconv ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        if( !GetHSZ( &str, &hdl ) ) {
            rc = ERR_INVALID_DDE;
            break;
        }
        data = DdeCreateDataHandle( DDEInstId, (LPBYTE)tmp1, strlen( tmp1 ) + 1,
                                    0L, hdl, ClipboardFormat, 0 );
        if( data == (HDDEDATA)NULL ) {
            rc = ERR_DDE_FAIL;
        } else {
            DdeClientTransaction( (LPBYTE)data, -1, hconv, hdl,
                                  ClipboardFormat, XTYP_POKE, TIME_OUT, NULL );
        }
        break;
    }

    *result = rc;
    return( true );

} /* RunDDECommand */
示例#3
0
HDDEDATA W_CALLBACK KapDDECallBack(WORD wTran, WORD wFmt, HCONV hConv,
				   HSZ hsz1, HSZ hsz2, HDDEDATA hData,
				   DWORD dwData1, DWORD dwData2)
{
    switch (wTran) {
      case XTYP_ADVSTART:
      case XTYP_ADVSTOP:
      {
          BOOL bRes = FALSE;
    
          if (wFmt == CF_TEXT)
          {
              char *cl;
              
              if (!DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                                  RET_BUFFER_LEN, CP_WINANSI))
                  return (HDDEDATA) FALSE;
              
              cl = strchr(return_buffer, ':');
              if (cl)
              {
                  DDEINFO ddeInfo;
                  ATOMID idName;
                  WORD wType;
                  
                  cl[0] = '\0';
                  idName = KppAddAtom(return_buffer);
                  ddeInfo.idSlot = KppAddAtom(cl + 1);
                  ddeInfo.idObj = KppGetObjectId(idName, &wType);
                  ddeInfo.idApp = ddeInfo.idItem = NULLID;
                  ddeInfo.idTopic = HszToAtom(hsz1);
                  ddeInfo.hConv = hConv;
                  
                  if (ddeInfo.idObj)
                  {
                      UnwindProtect(cleanup1);
                      requests++;
                      switch (wTran) {
                        case XTYP_ADVSTART:
                            if (CreateLink(&ddeInfo))
                                bRes = TRUE;
                            break;
                        case XTYP_ADVSTOP:
                            if (CloseServerLink(&ddeInfo, idName))
                                bRes = TRUE;
                            break;
                      }
                    cleanup1:
                      requests--;
                      EndProtect();
                  }
              }
          }

          return (HDDEDATA) bRes;                  
      }

      case XTYP_EXECUTE:
      {
          DWORD dwLen;
          LPBYTE lpByte = DdeAccessData(hData, &dwLen);
          
          if (lpByte)
          {
              BOOL bFree = FALSE;
              LPBYTE lpCopy;

              if (dwLen < RET_BUFFER_LEN)
              {
                  strcpy(return_buffer, lpByte);
                  lpCopy = return_buffer;
              }
              else
              {
                  lpCopy = strdup(lpByte);
                  bFree = TRUE;
              }
              DdeUnaccessData(hData);
          
              if (lpCopy)
              {
                  UnwindProtect(cleanup2);
                  requests++;
                  if (!KppEvalExpString(lpCopy))
                      KppPostKappaErrorMessageCB();
                cleanup2:
                  requests--;
                  if (bFree)
                      free(lpCopy);
                  EndProtect();
                  
                  return (HDDEDATA) DDE_FACK;
              }
          }
           
          return (HDDEDATA) DDE_FNOTPROCESSED;
      }
          
      case XTYP_CONNECT:
          if (DdeQueryString(dwDDEInst, hsz1, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))
          {
              char *dot = strrchr(return_buffer, '.');

              if (dot)
                  dot[0] = '\0';
              
              if (!stricmp(DDETopicName, return_buffer) ||
#ifdef MULTI
                  !stricmp(DDEKappaName, return_buffer) ||
                  S_ILOC == 0 &&
#endif
                  !stricmp("KAPPA", return_buffer))
                  return TRUE;
          }
          
          return (HDDEDATA) FALSE;
          
      case XTYP_DISCONNECT:
          UnwindProtect(cleanup3);
          requests++;
          DeleteDDETasks(hConv);
        cleanup3:
          requests--;
          EndProtect();
          return (HDDEDATA) NULL;
          
      case XTYP_WILDCONNECT:
      {
          HSZPAIR hszPair[3];
              
          hszPair[0].hszSvc = 
              DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI);
          hszPair[0].hszTopic = 
              DdeCreateStringHandle(dwDDEInst, DDETopicName, CP_WINANSI);
          hszPair[1].hszSvc = 
              DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI);
          hszPair[1].hszTopic = 
              DdeCreateStringHandle(dwDDEInst, DDEKappaName, CP_WINANSI);
          hszPair[2].hszSvc = hszPair[2].hszTopic = NULL;
          
          return DdeCreateDataHandle(dwDDEInst, (LPVOID) hszPair,
                                     sizeof(HSZPAIR) * 3, 0, 
                                     hszPair[0].hszSvc, CF_TEXT, 0);
      }
          
      case XTYP_POKE:
      {
          UINT flag = DDE_FNOTPROCESSED;
          
          if (wFmt == CF_TEXT &&
              DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))              
          {
              ATOMID idSlot;
              OBJECTID idObj;
              
              UnwindProtect(cleanup4);
              requests++;
              idObj = ObjSlotFromItem(return_buffer, &idSlot);
              if (idObj && StoreData(lpIDs->idNull, hData, idObj, idSlot))
                  flag = DDE_FACK;
            cleanup4:
              requests--;
              EndProtect();
          }

          return (HDDEDATA) flag;
      }
          
      case XTYP_REQUEST:
      case XTYP_ADVREQ:
          hData = (HDDEDATA) DDE_FNOTPROCESSED;
          if (wFmt == CF_TEXT &&
              DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))              
          {
              ATOMID idSlot;
              OBJECTID idObj;
              
              UnwindProtect(cleanup5);
              requests++;
              idObj = ObjSlotFromItem(return_buffer, &idSlot);
              if (idObj)
              {
                  BOOL bMulti = FALSE;
                  ITEMID idValue =
                      Kpp_Get_SlotAnyValue(OBJECT_TYPE(idObj),
                                           idObj, idSlot, (LPWORD) &bMulti);
                  GLOBALHANDLE hMem = NULL;
                  LPBYTE lpBytes = NULL;
                  DWORD dwLen = ValueToString(idValue, bMulti, 
                                              &hMem, &lpBytes);
                  
                  if (dwLen)
                  {
                      hData = DdeCreateDataHandle(dwDDEInst, lpBytes, dwLen,
                                                  0, hsz2, CF_TEXT, 0);
                      if (hMem)
                      {
                          GLOBALUNLOCK(hMem);
                          GLOBALFREE(hMem);
                      }
                      if (!hData)
                          hData = (HDDEDATA) DDE_FNOTPROCESSED;
                  }
              }
            cleanup5:
              requests--;
              EndProtect();
          }
          return hData;              
        
      case XTYP_REGISTER:
      {
          ATOMID idApp = HszToAtom(hsz2);
          
          UnwindProtect(cleanup6);
          requests++;
          if (idApp)
          {
              WORD wType;
              OBJECTID idService = KppGetObjectId(idApp, &wType);
              
              if (!idService)
              {
                  idService = KppMakeCO(OBJECT, idApp, idDDEService);
                  wType = OBJECT;
              }
              if (idService)
              {
                  if (DdeQueryString(dwDDEInst, hsz1, return_buffer, 
                                     RET_BUFFER_LEN, CP_WINANSI))
                      Kpp_Set_SlotValue(wType, idService, Slot(idService),
                                        KppAddAtom(return_buffer), EXPATOM);
                  else
                      Kpp_Set_SlotValue(wType, idService, Slot(idService),
                                        lpIDs->idNull, EXPATOM);
              }
          }
        cleanup6:
          requests--;
          EndProtect();
          
          return (HDDEDATA) NULL;
      }
        
      case XTYP_ADVDATA:
          UnwindProtect(cleanup7);
          requests++;
          if (wFmt == CF_TEXT)
          {
              CONVINFO ci;
              ATOMID idApp, idItem, idName;
              OBJECTID idLink;
              
              memset(&ci, 0, sizeof(CONVINFO));
              ci.cb = sizeof(CONVINFO);
              DdeQueryConvInfo(hConv, QID_SYNC, &ci);
              idApp = HszToAtom(ci.hszSvcPartner);
              idItem = HszToAtom(hsz2);
              idName = LinkName(idApp, idItem);
              idLink = FindLink(idName);
              
              if (idLink)
              {
                  WORD wDestType;
                  ATOMID idDest = Kpp_Get_SlotValue(OBJECT, idLink,
                                                    Slot(idDDEObject));
                  ATOMID idSlot = Kpp_Get_SlotValue(OBJECT, idLink,
                                                    Slot(idDDESlot));
                  OBJECTID idDestObj = KppGetObjectId(idDest, &wDestType);
              
                  StoreData(lpIDs->idNull, hData, idDestObj, idSlot);
              }
          }
        cleanup7:
          requests--;
          EndProtect();
          
          return (HDDEDATA) DDE_FACK;
          
      case XTYP_XACT_COMPLETE:
      {
          char name[20];
          OBJECTID idTask;
          ATOMID idName;
          WORD wType;
          
          UnwindProtect(cleanup8);
          requests++;
          task_name(name, hConv, dwData1);
          idName = KppAddAtom(name);
          idTask = KppGetObjectId(idName, &wType);
          
          if (idTask)
          {
              CONVINFO ci;

              memset(&ci, 0, sizeof(CONVINFO));
              ci.cb = sizeof(CONVINFO);
              DdeQueryConvInfo(hConv, dwData1, &ci);
          
              switch (ci.wType) {
                case XTYP_REQUEST:
                    if (wFmt == CF_TEXT)
                    {
                        WORD wDestType;
                        ATOMID idDest = Kpp_Get_SlotValue(wType, idTask, 
                                                          Slot(idDDEObject));
                        ATOMID idSlot = Kpp_Get_SlotValue(wType, idTask, 
                                                          Slot(idDDESlot));
                        OBJECTID idDestObj = KppGetObjectId(idDest, 
                                                            &wDestType);
              
                        StoreData(lpIDs->idNull, hData, idDestObj, idSlot);
                        DdeDisconnect(hConv);              
                    }
                    break;
                    
                case XTYP_POKE:
                case XTYP_EXECUTE:
                    DdeDisconnect(hConv);              
                    break;
                    
                case (XTYP_ADVSTART | XTYPF_ACKREQ):
                {
                    ATOMID idDest =
                        Kpp_Get_SlotValue(wType, idTask, Slot(idDDEObject));
                    WORD wDestType;
                    DDEINFO ddeInfo;

                    ddeInfo.hConv = hConv;
                    ddeInfo.idApp = Kpp_Get_SlotValue(wType, idTask, 
                                                      Slot(idService));
                    ddeInfo.idTopic = Kpp_Get_SlotValue(wType, idTask, 
                                                        Slot(idTopic));
                    ddeInfo.idItem = Kpp_Get_SlotValue(wType, idTask, 
                                                       Slot(idItem));
                    ddeInfo.idObj = KppGetObjectId(idDest, &wDestType);
                    ddeInfo.idSlot = Kpp_Get_SlotValue(wType, idTask, 
                                                       Slot(idDDESlot));
              
                    CreateLink(&ddeInfo);
                    break;
                }
              }

              DeleteDDETask(lpIDs->idNull, wType, idTask, (LPVOID) &hConv);
          }
        cleanup8:
          requests--;
          EndProtect();
          
          return (HDDEDATA) NULL;
      }
          
      default:
          return (HDDEDATA) NULL;
    }
}
示例#4
0
HDDEDATA FAR PASCAL _export DdeCallback(UINT type, UINT fmt,
                        HCONV hConv, HSZ hsz1, HSZ hsz2,
                        HDDEDATA data, DWORD data1,
                        DWORD data2)
{
  long int ind, i, spaceneeded, sizeQuery;
  DWORD Qlen, QSegLen;
  static HCONV handConv;
  static HDDEDATA hdDataHandle;

    /*DdeQueryString(idInst,hsz1,szBuff1,sizeof(szBuff1),0);
    DdeQueryString(idInst,hsz2,szBuff2,sizeof(szBuff2),0);
    
    fprintf(stderr,"DDE Callback, type=%d, fmt=%d, hConv=%d, hsz1=%s, hsz2=%s,\n d1=%x, d2=%x\n",
        type,fmt,hConv,szBuff1,szBuff2,data1,data2);*/

    
    switch (type) {
      case XTYP_ERROR:
        fprintf(stderr,"error: xtyp_error\n");
        return NULL;
      case XTYP_ADVDATA:
        fprintf(stderr,"DDE msg received ADVDATA\n");
        return DDE_FNOTPROCESSED;
      case XTYP_ADVREQ:
        fprintf(stderr,"DDE msg received ADVREQ\n");
        return NULL;
      case XTYP_ADVSTART:
        fprintf(stderr,"DDE msg received ADVSTART\n");
        return NULL;
      case XTYP_ADVSTOP:
        fprintf(stderr,"DDE msg received ADVSTOP\n");
        return NULL;
      
      case XTYP_CONNECT:
        DdeQueryString(idInst,hsz2,szBuffer,sizeof(szBuffer),0);
        if (strcmp(szBuffer,szAppName)) return FALSE;
        Qlen = DdeQueryString(idInst,hsz1,NULL,0,0);
        szQuery = (char *)malloc(Qlen+1);
        (void)DdeQueryString(idInst,hsz1,szQuery,Qlen+1,0);
        if (!strcmp(szQuery,"XSB")) {
            free(szQuery);
            szQuery = NULL;
        }
        return TRUE;

      case XTYP_CONNECT_CONFIRM:
        handConv = hConv;
        return TRUE;

      case XTYP_DISCONNECT:
        return NULL;
      case XTYP_EXECUTE:
        fprintf(stderr,"DDE msg received EXECUTE\n");
        return DDE_FNOTPROCESSED;

      case XTYP_POKE:
        QSegLen = DdeGetData(data,NULL,100000,0L);
        if (!szQuery) {
            szQuery = (char *)malloc(QSegLen);
            QSegLen = DdeGetData(data,szQuery,100000,0L);
            sizeQuery = QSegLen;
        } else {
            szQuery = (char *)realloc(szQuery,sizeQuery+QSegLen+1);
            QSegLen = DdeGetData(data,szQuery+sizeQuery,100000,0L);
            sizeQuery =+ QSegLen;
        }
        return DDE_FACK;
        
      case XTYP_REGISTER:
        fprintf(stderr,"DDE msg received REGISTER\n");
        return NULL;

      case XTYP_REQUEST:
        /*fprintf(stderr,"DDE msg received REQUEST:\n");*/
        if (!szQuery) return NULL;
        if (sizeBuff3 < 10) {
            szBuff3 = (char *)malloc(initsizeBuff3);
            sizeBuff3 = initsizeBuff3;
        }
        ind = 0;
        rcode = xsb_query_string(szQuery);      /* call the query */
        if (rcode) {
            strcpy(szBuff3+ind,"no\r");
            ind += 3;
        } else if (is_string(reg_term(2)) || p2c_arity(reg_term(2))==0) {
            strcpy(szBuff3+ind,"yes\r");
            ind += 4;
            while (!rcode) rcode = xsb_next();
        } else while (!rcode) {
            spaceneeded = ind + clenpterm(reg_term(2)) + 20;  /* fudge factor */
            if (spaceneeded > sizeBuff3) {
                while (spaceneeded > sizeBuff3) {sizeBuff3 = 2*sizeBuff3;}
                szBuff3 = realloc(szBuff3,sizeBuff3);
            }
            for (i=1; i<p2c_arity(reg_term(2)); i++) {
                printpterm(p2p_arg(reg_term(2),i),TRUE,szBuff3,&ind);
                strcpy(szBuff3+ind,"\t");
                ind += 1;
            }
            printpterm(p2p_arg(reg_term(2),p2c_arity(reg_term(2))),TRUE,szBuff3,&ind);
            strcpy(szBuff3+ind,"\r");
            ind += 1;
            rcode = xsb_next();
        }
        hdDataHandle = DdeCreateDataHandle(idInst,szBuff3,ind+1,0,hsz2,CF_TEXT,0);
        free(szQuery);
        szQuery = NULL;
        return hdDataHandle;

      case XTYP_WILDCONNECT:
        fprintf(stderr,"DDE msg received WILDCONNECT\n");
        return NULL;
      default:
        fprintf(stderr,"DDE msg received: %d\n",type);        
    }
    return NULL;
}
示例#5
0
HDDEDATA EXPENTRY _EXPORT _DDECallback(
    WORD wType,
    WORD wFmt,
    HCONV hConv,
    HSZ hsz1,
    HSZ hsz2,
    HDDEDATA hData,
    DWORD /* lData1 */,
    DWORD /* lData2 */)
{
    switch (wType)
    {
    case XTYP_CONNECT:
    {
        char topic_buf[100];
        char server_buf[100];
        DdeQueryString(DDEIdInst, hsz1, (LPSTR)topic_buf, sizeof(topic_buf),
                       CP_WINANSI);
        DdeQueryString(DDEIdInst, hsz2, (LPSTR)server_buf, sizeof(topic_buf),
                       CP_WINANSI);
        CDDEServer *server = DDEFindServer(server_buf);
        if (server)
        {
            CDDEConnection *connection =
                server->OnAcceptConnection(CString(topic_buf));
            if (connection)
            {
                connection->server = server;
                server->connections.AddTail(connection);
                connection->hConv = 0;
                connection->topic_name = topic_buf;
                DDECurrentlyConnecting = connection;
                return (DDERETURN)TRUE;
            }
        }
        else return (DDERETURN)0;
        break;
    }

    case XTYP_CONNECT_CONFIRM:
    {
        if (DDECurrentlyConnecting)
        {
            DDECurrentlyConnecting->hConv = hConv;
            DDECurrentlyConnecting = NULL;
            return (DDERETURN)TRUE;
        }
        else return 0;
        break;
    }

    case XTYP_DISCONNECT:
    {
        //InterlockedExchange((long*)&bDisconnected, 1);
        //CDDEConnection *connection = DDEFindConnection(hConv);
        //if (connection && connection->OnDisconnect())
        //{
        //  DDEDeleteConnection(hConv);  // Delete mapping: hConv => connection
        //  return (DDERETURN)TRUE;
        //}
        //else return (DDERETURN)0;
        return (DDERETURN)TRUE;
        break;
    }

    case XTYP_EXECUTE:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection)
        {
            DWORD len = DdeGetData(hData, (LPBYTE)(connection->buf_ptr), connection->buf_size, 0);
            DdeFreeDataHandle(hData);
            if (connection->OnExecute(connection->topic_name, connection->buf_ptr, (int)len, wFmt))
                return (DDERETURN)DDE_FACK;
            else
                return (DDERETURN)DDE_FNOTPROCESSED;
        } else return (DDERETURN)DDE_FNOTPROCESSED;
        break;
    }

    case XTYP_REQUEST:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection)
        {
            char item_name[200];
            DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
                           CP_WINANSI);

            int user_size = -1;
            char *data = connection->OnRequest(connection->topic_name, CString(item_name), &user_size, wFmt);
            if (data)
            {
                if (user_size < 0) user_size = strlen(data);

                HDDEDATA handle = DdeCreateDataHandle(DDEIdInst,
                                                      (LPBYTE)data, user_size + 1, 0, hsz2, wFmt, 0);
                return (DDERETURN)handle;
            } else return (DDERETURN)0;
        } else return (DDERETURN)0;
        break;
    }

    case XTYP_POKE:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection)
        {
            char item_name[200];
            DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
                           CP_WINANSI);
            DWORD len = DdeGetData(hData, (LPBYTE)(connection->buf_ptr), connection->buf_size, 0);
            DdeFreeDataHandle(hData);
            connection->OnPoke(connection->topic_name, CString(item_name), connection->buf_ptr, (int)len, wFmt);
            return (DDERETURN)DDE_FACK;
        } else return (DDERETURN)DDE_FNOTPROCESSED;
        break;
    }

    case XTYP_ADVSTART:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection)
        {
            char item_name[200];
            DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
                           CP_WINANSI);

            return (DDERETURN)connection->OnStartAdvise(connection->topic_name, CString(item_name));
        } else return (DDERETURN)0;
        break;
    }

    case XTYP_ADVSTOP:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection)
        {
            char item_name[200];
            DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
                           CP_WINANSI);
            return (DDERETURN)connection->OnStopAdvise(connection->topic_name, CString(item_name));
        } else return (DDERETURN)0;
        break;
    }

    case XTYP_ADVREQ:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection && connection->sending_data)
        {
            HDDEDATA data = DdeCreateDataHandle(DDEIdInst,
                                                (LPBYTE)connection->sending_data,
                                                connection->data_size, 0, hsz2, connection->data_type, 0);
            connection->sending_data = NULL;
            return (DDERETURN)data;
        } else return (DDERETURN)NULL;
        break;
    }

    case XTYP_ADVDATA:
    {
        CDDEConnection *connection = DDEFindConnection(hConv);

        if (connection)
        {
            char item_name[200];
            DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
                           CP_WINANSI);

            DWORD len = DdeGetData(hData, (LPBYTE)(connection->buf_ptr), connection->buf_size, 0);
            DdeFreeDataHandle(hData);
            if (connection->OnAdvise(connection->topic_name, CString(item_name), connection->buf_ptr, (int)len, wFmt))
                return (DDERETURN)DDE_FACK;
            else
                return (DDERETURN)DDE_FNOTPROCESSED;
        } else return (DDERETURN)DDE_FNOTPROCESSED;
        break;
    }
    }
    return 0;
}
示例#6
0
/*
 * DdeCallBack
 */
HDDEDATA CALLBACK DdeCallBack( WORD wType, WORD wFmt, HCONV hConv, HSZ hsz1, HSZ hsz2,
                               HDDEDATA hdata, ULONG_PTR lData1, ULONG_PTR lData2 )
{
    img_node            *node;
    HSZPAIR             hszpair[2];
    HDDEDATA            ret;
    int                 i;

    _imged_touch( wFmt );
    _imged_touch( hdata );
    _imged_touch( lData1 );
    _imged_touch( lData2 );

    ret = (HDDEDATA)NULL;

    switch( wType ) {
    case XTYP_CONNECT_CONFIRM:
        IEServerConv = hConv;
        break;

    case XTYP_DISCONNECT:
        IEServerConv = (HCONV)NULL;
        IEClientConv = (HCONV)NULL;
        SendMessage( HMainWindow, WM_CLOSE, (WPARAM)1, 0 );
        break;

    case XTYP_CONNECT:
        for( i = 0; i < NUM_FORMATS; i++ ) {
            if( IEServices[i].htopic == hsz1 ) {
                EditFormat = (IEEditFormat)i;
                ret = (HDDEDATA)TRUE;
            }
        }
        break;

    case XTYP_WILDCONNECT:
        for( i = 0; i < NUM_FORMATS; i++ ) {
            if( IEServices[i].hservice == hsz2 ) {
                break;
            }
        }
        if( i == NUM_FORMATS ) {
            break;
        }
        hszpair[0].hszSvc = IEServices[i].hservice;
        hszpair[0].hszTopic = IEServices[i].htopic;
        hszpair[1].hszSvc = (HSZ)NULL;
        hszpair[1].hszTopic = (HSZ)NULL;
        ret = (HDDEDATA)DdeCreateDataHandle( IdInst, (LPBYTE)&hszpair[0],
                                             sizeof( hszpair ), 0L, 0, CF_TEXT, 0 );
        break;

    case XTYP_REQUEST:
        if( wFmt == IEClipFormats[EditFormat].format ) {
            if( hsz1 == IEServices[EditFormat].htopic ) {
                node = IEGetCurrentImageNode();
                if( hsz2 == hDataItem ) {
                    ret = IECreateResData( node );
                }
            }
        }
        break;

    case XTYP_POKE:
        ret = (HDDEDATA)DDE_FNOTPROCESSED;
        if( hsz1 == IEServices[EditFormat].htopic ) {
            if( hsz2 == hDataItem ) {
                IEHandlePokedData( hdata );
                ret = (HDDEDATA)DDE_FACK;
            }
        }
        break;
    }

    return( ret );

} /* DdeCallback */
示例#7
0
HDDEDATA CALLBACK DdeCallBack( UINT wType, UINT wFmt, HCONV hConv,
                                HSZ hsz1, HSZ hsz2, HDDEDATA hdata,
                                ULONG_PTR lData1, ULONG_PTR lData2 )
{
    HDDEDATA    ret;
    HSZPAIR     hszpair[2];
    HSZ         htopic;
    HCONV       htconv;
    void        *data;
    uint_32     size;
    bool        ok;

    _wre_touch( hdata );
    _wre_touch( lData1 );
    _wre_touch( lData2 );

    ret = (HDDEDATA)FALSE;

    switch( wType ) {
    case XTYP_CONNECT:
    case XTYP_WILDCONNECT:
        if( PendingService == NoServicePending ) {
            htopic = (HSZ)NULL;
        } else {
            htopic = (HSZ)Topics[PendingService].htopic;
        }
        break;
    }

    switch( wType ) {
    case XTYP_CONNECT_CONFIRM:
        htconv = (HCONV)NULL;
        if( PendingService != NoServicePending ) {
                htconv = DdeConnect( IdInst, EditServers[PendingService].hservice,
                                     EditServers[PendingService].htopic, (LPVOID)NULL );
        }
        if( htconv != (HCONV)NULL ) {
            if( PendingService == DialogService ) {
                ok = WRECommitDialogSession( hConv, htconv );
            } else {
                ok = WRECommitImageSession( hConv, htconv );
            }
            if( !ok ) {
                DdeDisconnect( htconv );
                DdeDisconnect( hConv );
            }
        } else {
            DdeDisconnect( hConv );
        }
        break;

    case XTYP_DISCONNECT:
        if( !WREEndEditImageResource( hConv ) ) {
            WREEndEditDialogResource( hConv );
        }
        break;

    case XTYP_CONNECT:
        if( hsz1 == hDialogDump ) {
            WREDumpPendingDialogSession();
        } else if( hsz1 == hImageDump ) {
            WREDumpPendingImageSession();
        } else if( hsz1 == htopic ) {
            ret = (HDDEDATA)TRUE;
        }
        break;

    case XTYP_WILDCONNECT:
        if( hsz2 != hServiceName ) {
            break;
        }
        if( htopic == (HSZ)NULL ) {
            break;
        }
        hszpair[0].hszSvc = hServiceName;
        hszpair[0].hszTopic = htopic;
        hszpair[1].hszSvc = (HSZ)NULL;
        hszpair[1].hszTopic = (HSZ)NULL;
        ret = (HDDEDATA)DdeCreateDataHandle( IdInst, (LPBYTE)&hszpair[0], sizeof( hszpair ),
                                             0L, 0, CF_TEXT, 0 );
        break;

    case XTYP_REQUEST:
        data = NULL;
        size = 0;
        ok = false;
        if( hsz1 == Topics[DialogService].htopic ) {
            if( hsz2 == hFileItem ) {
                ok = WREGetDlgSessionFileName( hConv, &data, &size );
            } else if( hsz2 == hDataItem ) {
                ok = WREGetDlgSessionData( hConv, &data, &size );
            } else if( hsz2 == hNameItem ) {
                ok = WREGetDlgSessionResName( hConv, &data, &size );
            } else if( hsz2 == hIs32BitItem ) {
                ok = WREGetDlgSessionIs32Bit( hConv, &data, &size );
            }
        } else if( hsz1 == Topics[BitmapService].htopic ||
                   hsz1 == Topics[CursorService].htopic ||
                   hsz1 == Topics[IconService].htopic ) {
            if( hsz2 == hFileItem ) {
                ok = WREGetImageSessionFileName( hConv, &data, &size );
            } else if( hsz2 == hDataItem ) {
                ok = WREGetImageSessionData( hConv, &data, &size );
            } else if( hsz2 == hNameItem ) {
                ok = WREGetImageSessionResName( hConv, &data, &size );
            }
        }
        if( data != NULL ) {
            if( ok ) {
                ret = DdeCreateDataHandle( IdInst, (LPBYTE)data, size, 0, hsz2, wFmt, 0 );
            }
            WRMemFree( data );
        }
        break;

    case XTYP_POKE:
        data = NULL;
        size = 0;
        ok = false;
        ret = (HDDEDATA)DDE_FNOTPROCESSED;
        if( hsz1 == Topics[DialogService].htopic ) {
            if( hsz2 == hDataItem ) {
                ok = WRESetDlgSessionResData( hConv, hdata );
            } else if( hsz2 == hNameItem ) {
                ok = WRESetDlgSessionResName( hConv, hdata );
            }
        } else if( hsz1 == Topics[BitmapService].htopic ||
                   hsz1 == Topics[CursorService].htopic ||
                   hsz1 == Topics[IconService].htopic ) {
            if( hsz2 == hDataItem ) {
                ok = WRESetImageSessionResData( hConv, hdata );
            } else if( hsz2 == hNameItem ) {
                ok = WRESetImageSessionResName( hConv, hdata );
            }
        }
        ret = (HDDEDATA)DDE_FACK;
        break;
    }

    return( ret );
}
LRESULT CALLBACK MainWndProc ( HWND hWnd, UINT message,
                               WPARAM wParam, LPARAM lParam )
{
   HDC            hDC;
   PAINTSTRUCT    ps;
   DLGPROC        dlgProcAbout;
   int            i;
   int            j;
   short          y;


   switch ( message )
   {
      case WM_CREATE:
         hDC = GetDC ( hWnd );

         GetTextMetrics ( hDC, &tm );
         cxChar = tm.tmAveCharWidth;
         cyChar = tm.tmHeight + tm.tmExternalLeading;

         ReleaseDC ( hWnd, hDC );

         lpDdeProc = MakeProcInstance ( (FARPROC) DDECallback, hInst );
         if ( DdeInitialize ( (LPDWORD)&idInst, (PFNCALLBACK)lpDdeProc,
                              APPCMD_CLIENTONLY, 0L ) )
         {
            HandleOutput ( "Client DDE initialization failure." );
            return ( FALSE );
         }

         hszService = DdeCreateStringHandle ( idInst, "Borland", CP_WINANSI );
         hszTopic = DdeCreateStringHandle ( idInst, "DDEExample", CP_WINANSI );
         hszItem = DdeCreateStringHandle ( idInst, "DDEData", CP_WINANSI );

         cCurrentLine = 0;
         cTotalLines = 0;

         strcpy ( szDDEString, "Client application message number:  " );
         break;

      case WM_COMMAND:
         switch ( wParam )
         {
            case IDM_EXIT:
               DestroyWindow ( hWnd );
               break;

            case IDM_CONNECT_SERVER:
               if ( hConv == NULL )
               {
                  hConv = DdeConnect ( idInst, hszService, hszTopic,
                                       (PCONVCONTEXT) NULL );
                  if ( hConv == NULL )
                  {
                     HandleError ( DdeGetLastError ( idInst ) );
                     HandleOutput ( "Unsuccessful connection." );
                  }
                  else
                     HandleOutput ( "Successful connection." );
               }
               else
                  HandleOutput ( "Already connected to DDE Server." );

               break;

            case IDM_DISCONNECT_SERVER:
               if ( hConv != NULL )
               {
                  DdeDisconnect ( hConv );
                  hConv = NULL;
                  HandleOutput ( "Disconnected from server." );
               }
               else
                  HandleOutput ( "Must be connected before disconnecting." );

               break;

            case IDM_MSG_TO_SERVER:
               if ( hConv != NULL )
               {
                  iClientCount ++;
                  sprintf ( tbuf, "%3d.", iClientCount );
                  strncpy ( &szDDEString[36], tbuf, 5 );

                  hData = DdeCreateDataHandle ( idInst, &szDDEString,
                           sizeof ( szDDEString ), 0L, hszItem, wFmt, 0 );

                  if ( hData != NULL )
            		  hData = DdeClientTransaction ( (LPBYTE)hData, -1, hConv,
                               hszItem, wFmt, XTYP_POKE, 1000, &dwResult );
                  else
                     HandleOutput ( "Could not create data handle." );
               }
               else
                  HandleOutput ( "A connection to a DDE Server has not been established." );

               break;

            case IDM_MSG_FROM_SERVER:
               if ( hConv != NULL )
               {
                  hData = DdeClientTransaction ( NULL, 0, hConv,
                               hszItem, wFmt, XTYP_REQUEST, 1000, &dwResult );

                  if ( dwResult == DDE_FNOTPROCESSED )
                     HandleOutput ( "Data not available from server." );
                  else
                  {
                     DdeGetData ( hData, (LPBYTE) szDDEData, 80L, 0L );

                     if ( szDDEData != NULL )
                        HandleOutput ( szDDEData );
                     else
                        HandleOutput ( "Message from server is null." );
                  }
               }
               else
                  HandleOutput ( "A connection to a DDE Server has not been established." );

               break;

            case IDM_ABOUT:
               dlgProcAbout = (DLGPROC) MakeProcInstance ( (FARPROC)About, hInst );
               DialogBox ( hInst, "AboutBox", hWnd, dlgProcAbout );
               FreeProcInstance ( (FARPROC) dlgProcAbout );
               break;

            default:
               return ( DefWindowProc ( hWnd, message, wParam, lParam ) );
         }
         break;

      case WM_PAINT:
         hDC = BeginPaint ( hWnd, &ps );

         y = 0;

         for ( i = 0; i < cTotalLines; i ++ )
         {
            if ( cTotalLines == 8 )
               j = ( (cCurrentLine + 1 + i) % 9 );
            else
               j = i;         // can't do this if we clear window and start in middle of array

            TextOut ( hDC, 0, y, (LPSTR)(szScreenText[j]),
                                 lstrlen ( szScreenText[j] ) );
            y = y + cyChar;
         }

         EndPaint ( hWnd, &ps );
         break;

      case WM_DESTROY:
         if ( hConv != NULL )
         {
            DdeDisconnect ( hConv );
            hConv = NULL;
         }

         DdeFreeStringHandle ( idInst, hszService );
         DdeFreeStringHandle ( idInst, hszTopic );
         DdeFreeStringHandle ( idInst, hszItem );

         FreeProcInstance ( lpDdeProc );

         PostQuitMessage ( 0 );
         break;

      default:
         return ( DefWindowProc ( hWnd, message, wParam, lParam ) );
   }

   return ( FALSE );
}
示例#9
0
文件: DdeAPI.cpp 项目: sankubha/jdde
HDDEDATA CALLBACK DdeCallback(
    UINT uType,     // Transaction type.
    UINT uFmt,      // Clipboard data format.
    HCONV hconv,    // Handle to the conversation.
    HSZ hsz1,       // Handle to a string.
    HSZ hsz2,       // Handle to a string.
    HDDEDATA hdata, // Handle to a global memory object.
    DWORD dwData1,  // Transaction-specific data.
    DWORD dwData2)  // Transaction-specific data.

{
	JNIEnv *env;
	jvm->GetEnv((void **) &env, JNI_VERSION_1_4);

	env->PushLocalFrame(16);

	HDDEDATA result = NULL;

	UINT idThread = GetCurrentThreadId();

	if (CallbackManager == NULL) {
		jclass clazz = env->FindClass("com/google/code/jdde/ddeml/CallbackManager");
		CallbackManager = (jclass) env->NewGlobalRef(clazz);

		mGetIdInst = env->GetStaticMethodID(CallbackManager, "getIdInst", "(I)I");
		mBooleanCallback = env->GetStaticMethodID(clazz, "DdeBooleanCallback", "(Lcom/google/code/jdde/ddeml/CallbackParameters;)Z");
		mDataCallback = env->GetStaticMethodID(clazz, "DdeDataCallback", "(Lcom/google/code/jdde/ddeml/CallbackParameters;)[B");
		mFlagCallback = env->GetStaticMethodID(clazz, "DdeFlagCallback", "(Lcom/google/code/jdde/ddeml/CallbackParameters;)I");
		mNotificationCallback = env->GetStaticMethodID(clazz, "DdeNotificationCallback", "(Lcom/google/code/jdde/ddeml/CallbackParameters;)V");
		mWildConnectCallback = env->GetStaticMethodID(clazz, "DdeWildConnectCallback", "(Lcom/google/code/jdde/ddeml/CallbackParameters;)[Ljava/lang/String;");
	}

	UINT idInst = env->CallStaticIntMethod(CallbackManager, mGetIdInst, idThread);

	jobject jobj;
	jobject parameter = WrapCallbackParameters(env, idInst, idThread, uType,
			uFmt, hconv, hsz1, hsz2, hdata, dwData1, dwData2);

	switch (uType) {
	case XTYP_ADVSTART:
	case XTYP_CONNECT:
		result = (HDDEDATA) env->CallStaticBooleanMethod(CallbackManager, mBooleanCallback, parameter);
		break;
	case XTYP_ADVREQ:
	case XTYP_REQUEST:
		jobj = env->CallStaticObjectMethod(CallbackManager, mDataCallback, parameter);
		jbyteArray bArray = (jbyteArray) jobj;

		if (bArray != NULL) {
			jsize cb = env->GetArrayLength(bArray);
			jbyte *pSrc = env->GetByteArrayElements(bArray, 0);
			result = DdeCreateDataHandle(idInst, (LPBYTE) pSrc, cb, 0, hsz2, uFmt, 0);
			env->ReleaseByteArrayElements(bArray, pSrc, 0);
		}
		break;
	case XTYP_WILDCONNECT:
		jobj = env->CallStaticObjectMethod(CallbackManager, mWildConnectCallback, parameter);
		jobjectArray sArray = (jobjectArray) jobj;

		if (sArray != NULL) {
			jsize cb = env->GetArrayLength(sArray);
			jsize length = cb / 2;
			HSZPAIR* hszPair = (HSZPAIR*) malloc((length + 1) * sizeof(HSZPAIR));

			int j = 0;
			for (int i = 0; i < cb; ) {
				jstring str1 = (jstring) env->GetObjectArrayElement(sArray, i++);
				HSZ hsz1 = UtilCreateStringHandle(env, idInst, str1);

				jstring str2 = (jstring) env->GetObjectArrayElement(sArray, i++);
				HSZ hsz2 = UtilCreateStringHandle(env, idInst, str2);

				hszPair[j].hszSvc = hsz1;
				hszPair[j++].hszTopic = hsz2;
			}
			hszPair[j].hszSvc = NULL;
			hszPair[j++].hszTopic = NULL;

			result = DdeCreateDataHandle(idInst, (LPBYTE)&hszPair[0], sizeof(HSZPAIR) * j, 0L, 0, uFmt, 0);
		}
		break;
	case XTYP_ADVDATA:
	case XTYP_EXECUTE:
	case XTYP_POKE:
		result = (HDDEDATA) env->CallStaticIntMethod(CallbackManager, mFlagCallback, parameter);
		break;
	case XTYP_ADVSTOP:
	case XTYP_CONNECT_CONFIRM:
	case XTYP_DISCONNECT:
	case XTYP_ERROR:
	case XTYP_MONITOR:
	case XTYP_REGISTER:
	case XTYP_XACT_COMPLETE:
	case XTYP_UNREGISTER:
		env->CallStaticVoidMethod(CallbackManager, mNotificationCallback, parameter);
		break;
	}

	if (env->ExceptionOccurred()) {
		PostThreadMessage(GetCurrentThreadId(), 0x7F7F, 0, 0);
	}

	env->PopLocalFrame(NULL);
	return result;
}