Ejemplo n.º 1
0
BOOL DDEServer::PostAdvise(HSZ hItem)
{
    UINT lasterr;
    BOOL result=TRUE;
    char szerr[20];


    if (::DdePostAdvise(_idInst, _hTopic, hItem) == FALSE)
       result=FALSE;

    // get last error
    if (!result)
    {
       lasterr = DdeGetLastError(_idInst);
       if (lasterr) {
               _itoa(lasterr, szerr, 16);
               strcat(szerr, " - PA last error");

               MessageBox(NULL, szerr,  "bugboard.exe error", MB_OK | MB_ICONSTOP);

       }
    }
    return result;

}
Ejemplo n.º 2
0
HDDEDATA DDE::CreateDataHandle( void FAR *lpbdata, DWORD size, HSZ hItem)
{
    DWORD lasterr;
    char szerr[30];


    HDDEDATA result = ::DdeCreateDataHandle(_idInst,        // instance ID
                                 (LPBYTE)lpbdata,        // data to convert
                                 size,           // size of data
                                 0,              // offset of data
                                 hItem,          // corresponding string handle
                                 CF_TEXT, //OWNERDISPLAY,// clipboard format
                                 0);             // creation flags, system owns
    if (!result)
    {
       lasterr = DdeGetLastError(_idInst);
       if (lasterr) {
               _itoa(lasterr, szerr, 16);
               strcat(szerr, " - CDH last error");

               MessageBox(NULL, szerr,  "bugboard.exe error", MB_OK | MB_ICONSTOP);

       }
    }

    return result;
}
Ejemplo n.º 3
0
static const char *
dde_error_message(int errn)
{ const char *err;

  if ( errn <= 0 )
    errn = DdeGetLastError(ddeInst);

  switch(errn)
  { case DMLERR_ADVACKTIMEOUT:
    case DMLERR_DATAACKTIMEOUT:		
    case DMLERR_EXECACKTIMEOUT:
    case DMLERR_POKEACKTIMEOUT:
    case DMLERR_UNADVACKTIMEOUT:	err = "Timeout";		break;
    case DMLERR_BUSY:			err = "Service busy";		break;
    case DMLERR_DLL_NOT_INITIALIZED:	err = "DDL not initialised";	break;
    case DMLERR_INVALIDPARAMETER:	err = "Invalid parameter";	break;
    case DMLERR_MEMORY_ERROR:		err = "Memory error";		break;
    case DMLERR_NO_CONV_ESTABLISHED:	err = "No conversation";	break;
    case DMLERR_NO_ERROR:		err = "No error???";		break;
    case DMLERR_NOTPROCESSED:		err = "Not processed";		break;
    case DMLERR_POSTMSG_FAILED:		err = "PostMessage() failed";	break;
    case DMLERR_REENTRANCY:		err = "Reentrance";		break;
    case DMLERR_SERVER_DIED:		err = "Server died";		break;
    default:				err = "Unknown error";		break;
  }

  return err;
}
Ejemplo n.º 4
0
bool WREPokeData( HCONV conv, void *data, int size, bool retry )
{
    DWORD       result;
    UINT        err;
    bool        timeout;
    bool        ret;
    UINT        tries;

    if( conv == (HCONV)NULL || data == NULL || size == 0 ) {
        return( FALSE );
    }

    if( retry ) {
        tries = 8;
    } else {
        tries = 0;
    }

    for( ;; ) {
        ret = ( DdeClientTransaction( (LPBYTE)data, size, conv, hDataItem, CF_TEXT, XTYP_POKE, LONG_TIME_OUT, &result ) != 0 );
        if( !ret && tries-- != 0 ) {
            err = DdeGetLastError( IdInst );
            timeout = ((err & DMLERR_POKEACKTIMEOUT) != 0);
            if( !timeout ) {
                break;
            }
        } else {
            break;
        }
    }

    return( ret );
}
Ejemplo n.º 5
0
//Connect to DDE Server
int connectDDE(char* ServiceName, char* TopicName)
{

    //DDE requires special handles to Strings
    HSZ ServiceHSZ = DdeCreateStringHandle(Inst, ServiceName, 0);
    HSZ TopicHSZ = DdeCreateStringHandle(Inst, TopicName, 0);

    //Setup the connection between DDE client and server
    Conversation = DdeConnect(Inst, ServiceHSZ, TopicHSZ, NULL);

    DdeFreeStringHandle(Inst, ServiceHSZ);
    DdeFreeStringHandle(Inst, TopicHSZ);

    //If we recieve a handle then connection atempt was sucessul
    if (Conversation == NULL)
    {
        printf("Failed to Connect to DDE Server. Instance %d \n", Inst);
        DDEError(DdeGetLastError(Inst));
        return 1;
    }
    else
    {
        #ifdef _ddedebug
        printf("Connected DDE\n");
        #endif
        return 0;
    }
}
Ejemplo n.º 6
0
HDDEDATA DDEconversation::Execute(const char *cmd)
{
    DDEstring c(cmd);
    DWORD res = NULL;
    HDDEDATA hData = DdeClientTransaction(NULL, 0, hConv, c, CF_TEXT, XTYP_REQUEST, 30000, &res);
    if (hData == NULL)
        DdeGetLastError((DWORD)DDEbase::base);
    return hData;
}
Ejemplo n.º 7
0
bool WEXPORT WClient::connect( const char *service, const char *topic ) {
/***********************************************************************/

    _service = DdeCreateStringHandle( _procid, (char *)service, CP_WINANSI );
    _topic = DdeCreateStringHandle( _procid, (char *)topic, CP_WINANSI );
    _hconv = DdeConnect( _procid, _service, _topic, NULL );
    if( _hconv != NULL ) {
        _convMap.setThis( this, (WHANDLE)_hconv );
        _connected = true;
        return( true );
    }
    DdeGetLastError( _procid );
    return( false );
}
Ejemplo n.º 8
0
void Senddde(char* tempstr)
{
  try
  {
    //Connect to the service and request the topic
    if ((hcnv = DdeConnect(idInst, hszService, hszTopic, NULL)) == 0)
    {
      ColorStop();
      return;
    }

    //Start a DDE transaction
    if (DdeClientTransaction((LPBYTE)tempstr, strlen(tempstr)+1,
          hcnv, hszItem, CF_TEXT, XTYP_POKE, 5000, &dwResult) == 0)
    {
      UINT result = DdeGetLastError(idInst);
      switch (result)
      {
        case DMLERR_ADVACKTIMEOUT:
        case DMLERR_BUSY:
        case DMLERR_DATAACKTIMEOUT:
        case DMLERR_DLL_NOT_INITIALIZED:
        case DMLERR_EXECACKTIMEOUT:
        case DMLERR_INVALIDPARAMETER:
        case DMLERR_MEMORY_ERROR:
        case DMLERR_NO_CONV_ESTABLISHED:
        case DMLERR_NO_ERROR:
        case DMLERR_NOTPROCESSED:
        case DMLERR_POKEACKTIMEOUT:
        case DMLERR_POSTMSG_FAILED:
        case DMLERR_REENTRANCY:
        case DMLERR_SERVER_DIED:
        case DMLERR_UNADVACKTIMEOUT:
        default:
          ColorStop();
      }
    }

    //Free DDE
    DdeDisconnect(hcnv);
  }
  catch(...)
  {
    ErrorHandler("Exception thrown in Senddde()!");
  }
}
Ejemplo n.º 9
0
BOOL CDDEConnection::Execute(char *data, int size, int format)
{
    DWORD result;
    if (size < 0)
        size = strlen(data);

    size ++;
    HDDEDATA rt = DdeClientTransaction((LPBYTE)data, size, hConv,
                                       NULL, format, XTYP_EXECUTE, 5000, &result);
    if (!rt)
    {
        /*if (bDisconnected)
        	return TRUE;*/
        printf("Warning: DDE result is 0x%x\n", DdeGetLastError(DDEIdInst));
        printf("Failed to exe cmd: %s\n", data);
    }
    return (rt ? TRUE : FALSE);
}
Ejemplo n.º 10
0
word
pl_dde_request(term_t handle, term_t item,
	       term_t value, term_t timeout)
{ int hdl;
  int rval;
  int ddeErr;
  HSZ Hitem;
  DWORD result, valuelen;
  HDDEDATA Hvalue;
  long tmo;

  if ( !get_conv_handle(handle, &hdl) ||
       !get_hsz(item, &Hitem) )
    fail;
  if ( !PL_get_long(timeout, &tmo) )
    return PL_error(NULL, 0, NULL, ERR_TYPE, ATOM_integer, timeout);

  if ( tmo <= 0 )
    tmo = TIMEOUT_VERY_LONG;

  Hvalue = DdeClientTransaction(NULL, 0, conv_handle[hdl], Hitem, CF_TEXT,
				XTYP_REQUEST, (DWORD)tmo, &result);
  ddeErr = DdeGetLastError(ddeInst);
  DdeFreeStringHandle(ddeInst, Hitem);

  if ( Hvalue)
  { char * valuebuf;
    char * valuedata;
    valuedata = DdeAccessData(Hvalue, &valuelen);
    valuebuf = (char *)malloc((size_t)valuelen+1);
    strncpy(valuebuf, valuedata, valuelen+1);
    DdeUnaccessData(Hvalue);
    valuebuf[valuelen] = EOS;
    rval = PL_unify_string_chars(value, valuebuf);
    free(valuebuf);
    return rval;
  } else
  { const char * errmsg = dde_error_message(ddeErr);

    return PL_unify_term(value,
			 PL_FUNCTOR, FUNCTOR_error1, /* error(Message) */
			 PL_CHARS,   errmsg);
  }
}
Ejemplo n.º 11
0
//Complete a DDE query
char* queryDDE(char* ItemName, DWORD* DataLength)
{
    char* DataStr = NULL;

    HSZ ItemHSZ = DdeCreateStringHandle(Inst, ItemName, CP_WINANSI);

    //Get data in DDE format from the server
    HDDEDATA DataHandle = DdeClientTransaction(NULL, 0, Conversation, ItemHSZ, CF_TEXT, XTYP_REQUEST, Timeout, NULL); //need to check about NULL vs. nil here

    DdeFreeStringHandle(Inst, ItemHSZ);
       
    //If we get a handle to it we contrinue
    if (DataHandle == NULL)
    {
        printf("DDE Query \"%s\" Failed\n", ItemName);
        DDEError(DdeGetLastError(Inst));
    }        
    else
    {
        #ifdef _ddedebug
        printf("Completed DDE Transaction\n");
        #endif

        //Find out how much data we've got
        DdeAccessData(DataHandle, DataLength);
        DataStr = malloc(*DataLength);
                        
        //Convert the data to char
        DdeGetData(DataHandle, DataStr, *DataLength, 0);
            
        #ifdef _ddedebug            
        printf("Converted DDE Data %d byte(s)\n", *DataLength);
        printf("%s\n",DataStr);
        #endif

        DdeUnaccessData(DataHandle);
    }

    return DataStr;
}
Ejemplo n.º 12
0
BOOL DDEClient::ReConnect()
{
    UINT x;
    DWORD numshares, bytes;
    char szlasterror[20];
    _bResult = TRUE;


    _hConv = ::DdeConnect(_idInst, _hServer, _hTopic, NULL);

    if (_hConv == NULL || _hConv == 0L || _hConv == 0)
    {
        x = DdeGetLastError(_idInst);
        _itoa(x, szlasterror, 16);
        strcat(szlasterror, " - DdeConnect failed");

        MessageBox(NULL, (LPCTSTR)szlasterror,  "ERROR bugboard.exe", MB_OK | MB_ICONSTOP);

        _bResult = FALSE;

    }
    return _bResult;
}
Ejemplo n.º 13
0
/* Note: Progman DDE always returns a pointer to 0x00000001 on a successful result */
static void DdeExecuteCommand(DWORD instance, HCONV hConv, const char *strCmd, HDDEDATA *hData, UINT *err, int testParams)
{
    HDDEDATA command;

    command = DdeCreateDataHandle(instance, (LPBYTE) strCmd, strlen(strCmd)+1, 0, 0L, 0, 0);
    ok (command != NULL, "DdeCreateDataHandle Error %s.%s\n",
        GetDdeLastErrorStr(instance), GetStringFromTestParams(testParams));
    *hData = DdeClientTransaction((void *) command,
                                  -1,
                                  hConv,
                                  0,
                                  0,
                                  XTYP_EXECUTE,
                                  MS_TIMEOUT_VAL,
                                  NULL);

    /* hData is technically a pointer, but for Program Manager,
     * it is NULL (error) or 1 (success)
     * TODO: Check other versions of Windows to verify 1 is returned.
     * While it is unlikely that anyone is actually testing that the result is 1
     * if all versions of windows return 1, Wine should also.
     */
    if (*hData == NULL)
    {
        *err = DdeGetLastError(instance);
    }
    else
    {
        *err = DMLERR_NO_ERROR;
        todo_wine
        {
            ok(*hData == (HDDEDATA) 1, "Expected HDDEDATA Handle == 1, actually %p.%s\n",
               *hData, GetStringFromTestParams(testParams));
        }
    }
    DdeFreeDataHandle(command);
}
Ejemplo n.º 14
0
/****************************************************************************
 *                                                                          *
 *  FUNCTION   : CompleteTransaction()                                      *
 *                                                                          *
 *  PURPOSE    : This handles completed synchronous and asynchronous        *
 *               transactions as well as failed attempted transactions.     *
 *                                                                          *
 *  RETURNS    : TRUE  - If successful.                                     *
 *               FALSE - otherwise.                                         *
 *                                                                          *
 ****************************************************************************/
VOID CompleteTransaction(
HWND hwndInfoCtrl,
XACT *pxact)
{
    PSTR psz;
    
    if (pxact->ret) {
        /*
         * Successful transaction case
         */
        SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_LL,
                (DWORD)(LPSTR)"Completed");
    
        if (pxact->wType == XTYP_REQUEST) {
            /*
             * Show resulting data
             */
            psz = GetTextData((HDDEDATA)pxact->ret);
            SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_CENTER,
                    (DWORD)(LPSTR)psz);
            MyFree(psz);
            /*
             * free returned data since it is displayed.
             */
            DdeFreeDataHandle(pxact->ret);
            pxact->ret = 0L;
            SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_UR, NULL);
        }
    } else {
        /*
         * failed - show error result.
         */
        SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_LL,
                (DWORD)(LPSTR)Error2String(DdeGetLastError(idInst)));
    }
    pxact->fsOptions |= XOPT_COMPLETED;
}
Ejemplo n.º 15
0
HDDEDATA DDEClient::ClientTransaction(void FAR *lpbData, DWORD cbData,
                                        HSZ hItem, UINT uType, UINT uFmt)
{
    UINT lasterr;
    char szerr[20];


    HDDEDATA hData = ::DdeClientTransaction(
            (LPBYTE)lpbData,    // data to send to server
            cbData,             // size of data in bytes
            _hConv,             // conversation handle
            hItem,              // handle of item name string
            uFmt,               // clipboard format, CF_TEXT default
            uType,              // XTYP_* type
            _timeout,           // timeout duration in milliseconds
            NULL);              // transaction result, not used

    _bResult = (hData != FALSE);

    // get last error

    if (!_bResult)
    {
       lasterr = DdeGetLastError(_idInst);
          if (lasterr)
          {
               _itoa(lasterr, szerr, 16);
               strcat(szerr, " - CT last error");

               MessageBox(NULL, szerr,  "bugboard.exe error", MB_OK | MB_ICONSTOP);

          }
    }


    return hData;
}
Ejemplo n.º 16
0
static BOOL DDESendMess(CHAR *lpBuffer)
{
 CHAR szService[] = DDEDBG_APPNAME ;
 CHAR szTopic[] = DDEDBG_TOPIC;
 HSZ  hszService, hszTopic, hszItem ;
 HCONV hConv ;
 HDDEDATA hde;
 SINT i;

#ifdef LOG
LOGWrite("DDE","DDE:sm [%s]",lpBuffer);
#endif
 if (idInst==0)
 {
  if (DdeInitialize (&idInst, (PFNCALLBACK) &DdeCallback, APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0L))
     {
#ifdef LOG
		LOGWrite("DDE","Non inizializzo");
#endif
		return FALSE;
     }
 }

#ifdef LOG
 LOGWrite("DDE","DDE:sm 1 [%s]",lpBuffer);
#endif
 // Try connecting

 hszService = DdeCreateStringHandle (idInst , szService, 0) ;
 hszTopic   = DdeCreateStringHandle (idInst , szTopic,   0) ;

 hConv = DdeConnect (idInst , hszService, hszTopic, NULL) ;

#ifdef LOG
 if (hConv==NULL) LOGWrite("DDE","Non trovo il server");
#endif
 // Se non c'è il server lo attivo
/*
 if (hConv == NULL)
 {
  WinExec ("c:\\eh3\\develop\\ddedbg.exe", SW_NORMAL) ;
  hConv = DdeConnect (idInst, hszService, hszTopic, NULL) ;
 }
*/
#ifdef LOG
LOGWrite("DDE","DDE:sm 2 [%s]",lpBuffer);
#endif
 // Free the string handles
 DdeFreeStringHandle (idInst , hszService) ;
 DdeFreeStringHandle (idInst , hszTopic) ;

#ifdef LOG
 LOGWrite("DDE","DDE:sm 3 [%s]",lpBuffer);
#endif
 // If still not connected, display message box
if (hConv == NULL)
{
	dispx("DDDebug.server non presente."); 
	return FALSE;
 }

#ifdef LOG
 LOGWrite("DDE","DDE:sm 4 [%s]",lpBuffer);
#endif
 hszItem = DdeCreateStringHandle (idInst , lpBuffer, 0) ;

 for (i=0;i<30;i++)
 {
//  hde=DdeClientTransaction (NULL, 0, hConv, hszItem, CF_TEXT,XTYP_ADVSTART | XTYPF_ACKREQ,DDE_TIMEOUT, NULL) ;
  hde=DdeClientTransaction (lpBuffer, strlen(lpBuffer)+1, hConv, 0L, CF_TEXT,XTYP_EXECUTE,DDE_TIMEOUT, NULL) ;
#ifdef LOG
  if (hde==0)
  {
	LOGWrite("DDE","Error=%d",DdeGetLastError(idInst));	 
  }
  else 
#endif
  break;
 }
//DMLERR_LOW_MEMORY
 
 DdeFreeStringHandle (idInst , hszItem) ;
 return TRUE;
}
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 );
}
Ejemplo n.º 18
0
/* Helper Function to Transfer DdeGetLastError into a String */
static const char * GetDdeLastErrorStr(DWORD instance)
{
    UINT err = DdeGetLastError(instance);

    return GetStringFromError(err);
}
Ejemplo n.º 19
0
/*****************************************************************
 *            DdeGetLastError  (DDEML.20)
 */
UINT16 WINAPI DdeGetLastError16(DWORD idInst)
{
    return (UINT16)DdeGetLastError(idInst);
}
Ejemplo n.º 20
0
BOOL MessageDDE ( WPARAM wParam )
  {
	switch ( wParam )
	  {
		case IDM_BUFFER_BATCH:
		case IDM_BUFFER_LOAD:
		case IDM_BUFFER_LBUF:
		  {
			extern HSZ hSZService, hSZItem;
			extern HCONV hConv;
			extern DWORD idInst;
			extern HWND hEditWnd;
			HANDLE hTemp;
			HSZ hSZTopic;
			DWORD dwResult;
			HDDEDATA hData;
			DWORD sel;
			int len;
			WORD start;
			char *Data;
			int text_length; // GDR

			/*--------------------------+
			| Create conversation Topic |
			+--------------------------*/

			if ( wParam == IDM_BUFFER_BATCH )
			  hSZTopic = DdeCreateStringHandle( idInst, "BATCH", CP_WINANSI);
			else
			  hSZTopic = DdeCreateStringHandle( idInst, "LOAD", CP_WINANSI);

			/*---------------------+
			| Selected entire File |
			+---------------------*/

			if ( wParam == IDM_BUFFER_LBUF )
			  SendMessage ( hEditWnd, EM_SETSEL, 0, -1);

			/*----------------------------------------+
			| Find the area of text that was selected |
			+----------------------------------------*/

			sel = SendMessage(hEditWnd,EM_GETSEL,0,0L);
			len = HIWORD(sel)- LOWORD(sel);
			start = LOWORD (sel);

			/*-------------------------------+
			| Start conversation with server |
			+-------------------------------*/

			if ( hConv != NULL ) DdeDisconnect ( hConv );
			hConv = DdeConnect ( idInst, hSZService, hSZTopic, (PCONVCONTEXT)NULL);
			if ( hConv == NULL )
			  {
				DdeFreeStringHandle ( idInst, hSZTopic );
				return ( FALSE );
			  }

			/*----------------------------+
			| Find Data that was Selected |
			+----------------------------*/

			// Begin GDR
			// hEditHandle = (HLOCAL) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0);
			// Data = (char *) LocalLock ( hEditHandle );
			text_length = SendMessage(hEditWnd,WM_GETTEXTLENGTH,0,0);
			Data = (char *) malloc(text_length+1);
			if (Data == NULL )
			  {
				MessageBeep ( 0 );
				MessageBox (NULL,"Can not complete operation",
					"Memory Low", MB_ICONSTOP | MB_TASKMODAL );
				DdeDisconnect( hConv );
				DdeFreeStringHandle ( idInst, hSZTopic );
				return(FALSE);
			  }

			SendMessage(hEditWnd,WM_GETTEXT,text_length+1,
							(LPARAM) Data);
			// End GDR

			/*------------------------------------------+
			| Create Packet Data and Copy Selected Data |
			+------------------------------------------*/

			hTemp = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, len + 1 );
			if ( hTemp == NULL )
			  {
				MessageBeep ( 0 );
				MessageBox (NULL,"Can not complete operation",
								"Memory Low", MB_ICONSTOP | MB_TASKMODAL );
				free(Data); // GDR
				DdeDisconnect( hConv );
				DdeFreeStringHandle ( idInst, hSZTopic );
				return(FALSE);
			  }
			{
			BYTE *Temp;
			int x;

			Temp = (BYTE *) GlobalLock ( hTemp );

			strncpy ( (char *) Temp, Data+start, len );

			for (x=0; x< len; x++ )
			  if ( Temp[x] == '\r' )
				 Temp[x] = ' ';
			Temp[len] = '\0';

			hData = DdeCreateDataHandle ( idInst, Temp, len+1 ,
						0L, hSZItem, CF_TEXT, 0 );
			if ( hData == NULL )
			  {
				free(Data); // GDR
				DdeDisconnect( hConv );
				DdeFreeStringHandle ( idInst, hSZTopic );
				GlobalUnlock ( hTemp );
				GlobalFree   ( hTemp );
				return ( FALSE );
			  }

			/*-------------------------------------------------+
			| Pass DDE Data Via XTYP_POKE DdeClientTransaction |
			+-------------------------------------------------*/

			DdeClientTransaction ((LPBYTE)hData, -1, hConv, hSZItem, CF_TEXT,
							 XTYP_POKE, 1000, &dwResult );

			if ( DdeGetLastError ( idInst ) == DMLERR_BUSY )
			  {
				MessageBeep ( 0 );
				MessageBox (NULL,"Can not complete operation",
						  "CLIPS Running.", MB_ICONSTOP | MB_TASKMODAL );
				free(Data); // GDR
				DdeDisconnect( hConv );
				DdeFreeStringHandle ( idInst, hSZTopic );
				GlobalUnlock ( hTemp );
				GlobalFree   ( hTemp );
				return(FALSE);
			  }

			GlobalUnlock ( hTemp );
			GlobalFree   ( hTemp );
			}

			// LocalUnlock ( hEditHandle);
			free(Data); // GDR
			DdeDisconnect( hConv );
			DdeFreeStringHandle ( idInst, hSZTopic );
			break;
		  }

		case IDM_HELP_COMPLETE:
		case IDM_EDIT_COMPLETE:
		  {
			extern DWORD idInst;
			extern HCONV hConv;
			extern HSZ hSZService, hSZItem;
			extern HWND hEditWnd;
			HSZ hSZTopic;
			DWORD dwResult;
			HDDEDATA hData;

			/*-------------------------------+
			| Start conversation with server |
			+-------------------------------*/

			hSZTopic = DdeCreateStringHandle ( idInst, "COMPLETE", CP_WINANSI );
			if ( hConv != NULL ) DdeDisconnect ( hConv );
			hConv = DdeConnect ( idInst, hSZService, hSZTopic, (PCONVCONTEXT)NULL);
			if ( hConv == NULL )
			  {
				DdeFreeStringHandle ( idInst, hSZTopic );
				return ( FALSE );
			  }

			/*--------------------+
			| Find and Send Token |
			+--------------------*/

			{
			// HANDLE hEditHandle;
			int text_length; // GDR
			DWORD sel = SendMessage(hEditWnd,EM_GETSEL,0,0L);
			WORD start = LOWORD (sel);
			WORD end;
			int len;
			BYTE *buffer;
			char *EditData;

			/*-------------------------+
			| Find Token to be matched |
			+-------------------------*/

			text_length = SendMessage(hEditWnd,WM_GETTEXTLENGTH,0,0);
			EditData = (char *) malloc(text_length+1);
			if ( EditData == NULL )
			  {
				DdeDisconnect(hConv);
				DdeFreeStringHandle ( idInst, hSZTopic );
				return ( FALSE );
			  }

			SendMessage(hEditWnd,WM_GETTEXT,text_length+1,(LPARAM) EditData);
			// hEditHandle = (HLOCAL) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0);
			// EditData = (char *) LocalLock ( hEditHandle );

			while (start > 0 && !(isspace(EditData[start-1])))
			  {start --;}
			end = start;

			while (!(isspace(EditData[end])))
			  { end ++; }

			len = (end - start)+1;
			buffer = (BYTE *) malloc ( len + 1);
			if (buffer == NULL )
			  {
				MessageBeep ( 0 );
				MessageBox (NULL,"Can not complete operation",
						 "Memory Low", MB_ICONSTOP | MB_TASKMODAL );
				free(EditData);
				DdeDisconnect(hConv);
				DdeFreeStringHandle ( idInst, hSZTopic );
				return(FALSE);
			  }
			strncpy ( (char *) buffer, EditData+start, len );

			/*--------------------------+
			| Create Data Packet & Send |
			+--------------------------*/

			hData = DdeCreateDataHandle ( idInst, buffer,
			  (DWORD) (len)+1, 0, hSZItem, CF_TEXT, 0 );
			if ( hData == NULL )
			  {
				DdeDisconnect(hConv);
				DdeFreeStringHandle ( idInst, hSZTopic );
				free(buffer);
				free(EditData);
				return ( FALSE );
			  }

			DdeClientTransaction ((LPBYTE)hData, -1, hConv, hSZItem, CF_TEXT, XTYP_POKE, 1000, &dwResult);
			free ( buffer );
			// LocalUnlock ( hEditHandle );
			free(EditData);
			// Begin GDR
			SendMessage ( hEditWnd, EM_SETSEL, start, end);
			// End GDR
			}

			/*---------------------------+
			| Retrieve and replace token |
			+---------------------------*/
			{
			char *buffer;

			/*----------------+
			| Wait for Result |
			+----------------*/

			hData = NULL;
			while ( hData == FALSE )
			  {
				hData = DdeClientTransaction ( NULL, 90, hConv,
					 hSZItem, CF_TEXT, XTYP_REQUEST, 100, &dwResult );
			  }

			/*------------+
			| Copy Result |
			+------------*/

			SetFocus ( hEditWnd );
			buffer = (char*)DdeAccessData (hData, NULL);
			if ( strcmp ( buffer, "\0" ) != 0 )
			  SendMessage ( hEditWnd, EM_REPLACESEL, 0,
					 (LPARAM)((LPSTR) buffer));
			DdeUnaccessData (hData);
			}

			/*----------------------+
			| ShutDown Conversation |
			+----------------------*/

			DdeDisconnect(hConv);
			DdeFreeStringHandle ( idInst, hSZTopic );
			break;
		  }
	  }
	return ( TRUE );
  }
Ejemplo n.º 21
0
/*------------------------------*/ BOOL     //--------------------------------
/*module ::*/                                                        DDE_Error
(
DWORD   DDEIdentifier ,
const String&  FunctionNameRef ,
const String&  MessageRef
)
   {
   BOOL   Error_Occured  =  FALSE;
   
   int  DDE_Error_Number = DdeGetLastError( DDEIdentifier );
   if(  DDE_Error_Number !=  DMLERR_NO_ERROR )
      {
		String	Error_String;
		switch( DDE_Error_Number )
			{
			case DMLERR_ADVACKTIMEOUT : 
					{ Error_String = "ADVACKTIMEOUT";       break; } 
			case DMLERR_BUSY :              
					{ Error_String = "BUSY";                break; } 
			case DMLERR_DATAACKTIMEOUT : 
					{ Error_String = "DATAACKTIMEOUT";      break; } 
		   case DMLERR_DLL_NOT_INITIALIZED : 
					{ Error_String = "DLL_NOT_INITIALIZED"; break; } 
		   case DMLERR_DLL_USAGE : 
					{ Error_String = "DLL_USAGE";           break; } 
		   case DMLERR_EXECACKTIMEOUT : 
					{ Error_String = "EXECACKTIMEOUT";      break; } 
		   case DMLERR_INVALIDPARAMETER : 
					{ Error_String = "INVALIDPARAMETER";    break; } 
		   case DMLERR_LOW_MEMORY : 
					{ Error_String = "LOW_MEMORY";          break; } 
		   case DMLERR_MEMORY_ERROR : 
					{ Error_String = "MEMORY_ERROR";        break; } 
		   case DMLERR_NO_CONV_ESTABLISHED : 
					{ Error_String = "NO_CONV_ESTABLISHED"; break; } 
		   case DMLERR_NOTPROCESSED : 
					{ Error_String = "NOTPROCESSED";        break; } 
		   case DMLERR_POKEACKTIMEOUT : 
					{ Error_String = "POKEACKTIMEOUT";      break; } 
		   case DMLERR_POSTMSG_FAILED : 
					{ Error_String = "POSTMSG_FAILED";      break; } 
		   case DMLERR_REENTRANCY : 
					{ Error_String = "REENTRANCY";          break; } 
		   case DMLERR_SERVER_DIED : 
					{ Error_String = "SERVER_DIED";         break; } 
		   case DMLERR_SYS_ERROR : 
					{ Error_String = "SYS_ERROR";           break; } 
		   case DMLERR_UNADVACKTIMEOUT :
					{ Error_String = "UNADVACKTIMEOUT";     break; } 
		   case DMLERR_UNFOUND_QUEUE_ID :
					{ Error_String = "UNFOUND_QUEUE_ID";    break; } 
			default:
				{
				String   Error_Number( 10, "", ' ' );
				_itoa( DDE_Error_Number, (char*)Error_Number, 10 );
      		Error_String = Error_Number;
				}
			
			} //end switch on error number
      String   Error_Msg( "DDE error: " );
		Error_Msg = Error_Msg 
                + Error_String 
                + ": "
                + MessageRef;
		MessageBox( NULL, Error_Msg, FunctionNameRef, MB_OK );		
      Error_Occured = TRUE;      
		}//end if error occured
   
	return   Error_Occured;   
   }
Ejemplo n.º 22
0
void DDEPrintError(void)
{
    char *err = NULL;
    switch (DdeGetLastError(DDEIdInst))
    {
    case DMLERR_ADVACKTIMEOUT:
        err = "A request for a synchronous advise transaction has timed out.";
        break;
    case DMLERR_BUSY:
        err = "The response to the transaction caused the DDE_FBUSY bit to be set.";
        break;
    case DMLERR_DATAACKTIMEOUT:
        err = "A request for a synchronous data transaction has timed out.";
        break;
    case DMLERR_DLL_NOT_INITIALIZED:
        err = "A DDEML function was called without first calling the DdeInitialize function,\n\ror an invalid instance identifier\n\rwas passed to a DDEML function.";
        break;
    case DMLERR_DLL_USAGE:
        err = "An application initialized as APPCLASS_MONITOR has\n\rattempted to perform a DDE transaction,\n\ror an application initialized as APPCMD_CLIENTONLY has \n\rattempted to perform server transactions.";
        break;
    case DMLERR_EXECACKTIMEOUT:
        err = "A request for a synchronous execute transaction has timed out.";
        break;
    case DMLERR_INVALIDPARAMETER:
        err = "A parameter failed to be validated by the DDEML.";
        break;
    case DMLERR_LOW_MEMORY:
        err = "A DDEML application has created a prolonged race condition.";
        break;
    case DMLERR_MEMORY_ERROR:
        err = "A memory allocation failed.";
        break;
    case DMLERR_NO_CONV_ESTABLISHED:
        err = "A client's attempt to establish a conversation has failed.";
        break;
    case DMLERR_NOTPROCESSED:
        err = "A transaction failed.";
        break;
    case DMLERR_POKEACKTIMEOUT:
        err = "A request for a synchronous poke transaction has timed out.";
        break;
    case DMLERR_POSTMSG_FAILED:
        err = "An internal call to the PostMessage function has failed. ";
        break;
    case DMLERR_REENTRANCY:
        err = "Reentrancy problem.";
        break;
    case DMLERR_SERVER_DIED:
        err = "A server-side transaction was attempted on a conversation\n\rthat was terminated by the client, or the server\n\rterminated before completing a transaction.";
        break;
    case DMLERR_SYS_ERROR:
        err = "An internal error has occurred in the DDEML.";
        break;
    case DMLERR_UNADVACKTIMEOUT:
        err = "A request to end an advise transaction has timed out.";
        break;
    case DMLERR_UNFOUND_QUEUE_ID:
        err = "An invalid transaction identifier was passed to a DDEML function.\n\rOnce the application has returned from an XTYP_XACT_COMPLETE callback,\n\rthe transaction identifier for that callback is no longer valid.";
        break;
    default:
        err = "Unrecognised error type.";
        break;
    }
    //MessageBox(NULL, (LPCSTR)err, "DDE Error", MB_OK | MB_ICONINFORMATION);
}
Ejemplo n.º 23
0
JNIEXPORT jint JNICALL Java_com_google_code_jdde_ddeml_DdeAPI_GetLastError
  (JNIEnv *env, jclass cls, jint idInst)
{
	return DdeGetLastError(idInst);
}