/**************************************************************************** * * * FUNCTION : GetTextData() AE: taken from DDEML sample app. Not * * currently used. * * * * PURPOSE : Allocates and returns a pointer to the data contained in * * hData. This assumes that hData points to text data and * * will properly handle huge text data by leaving out the * * middle of the string and placing the size of the string * * into this string portion. * * * * RETURNS : A pointer to the allocated string. * * * ****************************************************************************/ unsigned char * CURLProcessor::GetTextData( HDDEDATA hData) { unsigned char * psz; DWORD cb; #define CBBUF 1024 if (hData == NULL) { return(NULL); } cb = DdeGetData(hData, NULL, 0, 0); if (!hData || !cb) return NULL; if (cb > CBBUF) { //warn_check_retval_of_malloc; psz = (unsigned char *)malloc(sizeof CBBUF); DdeGetData(hData, (unsigned char *)psz, CBBUF - 46, 0L); } else { psz = (unsigned char *)malloc((WORD)cb); DdeGetData(hData, (unsigned char *)psz, cb, 0L); } return psz; #undef CBBUF }
/**************************************************************************** * * * FUNCTION : GetTextData() * * * * PURPOSE : Allocates and returns a pointer to the data contained in * * hData. This assumes that hData points to text data and * * will properly handle huge text data by leaving out the * * middle of the string and placing the size of the string * * into this string portion. * * * * RETURNS : A pointer to the allocated string. * * * ****************************************************************************/ PSTR GetTextData( HDDEDATA hData) { PSTR psz; DWORD cb; #define CBBUF 1024 if (hData == NULL) { return(NULL); } cb = DdeGetData(hData, NULL, 0, 0); if (!hData || !cb) return NULL; if (cb > CBBUF) { // possibly HUGE object! psz = MyAlloc(CBBUF); DdeGetData(hData, psz, CBBUF - 46, 0L); wsprintf(&psz[CBBUF - 46], "<---Size=%ld", cb); } else { psz = MyAlloc((WORD)cb); DdeGetData(hData, (LPBYTE)psz, cb, 0L); } return psz; #undef CBBUF }
static word unify_hdata(term_t t, HDDEDATA data) { BYTE buf[FASTBUFSIZE]; DWORD len; if ( !(len=DdeGetData(data, buf, sizeof(buf), 0)) ) return dde_warning("data handle"); DEBUG(1, Sdprintf("DdeGetData() returned %ld bytes\n", (long)len)); if ( len == sizeof(buf) ) { if ( (len=DdeGetData(data, NULL, 0, 0)) > 0 ) { LPBYTE b2; int rval; if ( !(b2 = malloc(len)) ) return PL_no_memory(); DdeGetData(data, b2, len, 0); rval = PL_unify_wchars(t, PL_ATOM, len/sizeof(wchar_t)-1, (wchar_t*)b2); free(b2); return rval; } return dde_warning("data handle"); } return PL_unify_wchars(t, PL_ATOM, len/sizeof(wchar_t)-1, (wchar_t*)buf); }
/* * IEHData2Mem */ BOOL IEHData2Mem( HDDEDATA hData, void **mem, uint_32 *size ) { if( hData == (HDDEDATA)NULL || mem == NULL || size == NULL ) { return( FALSE ); } *size = (uint_32)DdeGetData( hData, NULL, 0, 0 ); if( *size == 0 ) { return( FALSE ); } *mem = MemAlloc( *size ); if( *mem == NULL ) { return( FALSE ); } if( (DWORD)*size != DdeGetData( hData, *mem, (DWORD)*size, 0 ) ) { MemFree( *mem ); *mem = NULL; return( FALSE ); } return( TRUE ); } /* IEHData2Mem */
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. { if(uType==XTYP_ADVDATA && uFmt==CF_TEXT) { HSZ hszItem1 = DdeCreateStringHandle(idInst, szItem1, 0); HSZ hszItem2 = DdeCreateStringHandle(idInst, szItem2, 0); char szResult[255]; if((!DdeCmpStringHandles(hsz1, hszTopic)) && (!DdeCmpStringHandles(hsz2, hszItem1))) { DdeGetData(hdata, (unsigned char *)szResult, 255, 0); printf("%s - %s\n", szItem1,szResult); } else if((!DdeCmpStringHandles(hsz1, hszTopic)) && (!DdeCmpStringHandles(hsz2, hszItem2))) { DdeGetData(hdata, (unsigned char *)szResult, 255, 0); printf("%s - %s\n", szItem2,szResult); } } return 0; }
bool WREHData2Mem( HDDEDATA hData, void **data, uint_32 *size ) { DWORD dde_size; if( data == NULL || size == NULL || hData == (HDDEDATA)NULL ) { return( FALSE ); } *size = dde_size = DdeGetData( hData, NULL, 0, 0 ); if( dde_size == 0 ) { return( FALSE ); } *data = WRMemAlloc( dde_size ); if( *data == NULL ) { return( FALSE ); } if( dde_size != DdeGetData( hData, *data, dde_size, 0 ) ) { WRMemFree( *data ); return( FALSE ); } return( TRUE ); }
static int unify_hdata(term_t t, HDDEDATA data) { char buf[FASTBUFSIZE]; int len; if ( !(len=DdeGetData(data, buf, sizeof(buf)-1, 0)) ) return dde_warning("data handle"); DEBUG(0, Sdprintf("DdeGetData() returned %d bytes\n", len)); if ( len == sizeof(buf)-1 ) { if ( (len=DdeGetData(data, NULL, 0, 0)) > 0 ) { char *b2 = malloc(len+1); int rval; DdeGetData(data, b2, len, 0); b2[len] = 0; rval = PL_unify_atom_chars(t, b2); free(b2); return rval; } return dde_warning("data handle"); } buf[len] = 0; return PL_unify_atom_chars(t, buf); }
void *WdeHData2Mem( HDDEDATA hData ) { void *mem; uint_32 size; if( hData == (HDDEDATA)NULL ) { return( NULL ); } size = (uint_32)DdeGetData( hData, NULL, 0, 0 ); if( size == 0 ) { return( NULL ); } mem = WRMemAlloc( size ); if( mem == NULL ) { return( NULL ); } if( (DWORD)size != DdeGetData( hData, mem, (DWORD)size, 0 ) ) { WRMemFree( mem ); return( NULL ); } return( mem ); }
HDDEDATA CALLBACK init_callback (UINT uType, UINT uFmt, HCONV hconv, HSZ hsz1, HSZ hsz2, HDDEDATA hdata, DWORD dwData1, DWORD dwData2) { if (uType == XTYP_ADVDATA) { DWORD len = DdeGetData(hdata, NULL, 0, 0); char *buf = (char *)_alloca(len + 1); DdeGetData(hdata, (LPBYTE) buf, len + 1, 0); return (HDDEDATA) DDE_FACK; } return (HDDEDATA) NULL; }
/* Dde callback, save the execute or request string for processing */ static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, ULONG_PTR dwData1, ULONG_PTR dwData2) { DWORD size = 0, ret = 0; WINE_TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08lx, %08lx\n", uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2); switch (uType) { case XTYP_CONNECT: if (!DdeCmpStringHandles(hsz1, hszTopic)) return (HDDEDATA)TRUE; return (HDDEDATA)FALSE; case XTYP_EXECUTE: if (!(size = DdeGetData(hData, NULL, 0, 0))) WINE_ERR("DdeGetData returned zero size of execute string\n"); else if (!(ddeString = HeapAlloc(GetProcessHeap(), 0, size))) WINE_ERR("Out of memory\n"); else if (DdeGetData(hData, (LPBYTE)ddeString, size, 0) != size) WINE_WARN("DdeGetData did not return %d bytes\n", size); DdeFreeDataHandle(hData); return (HDDEDATA)DDE_FACK; case XTYP_REQUEST: ret = -3; /* error */ if (!(size = DdeQueryStringW(ddeInst, hsz2, NULL, 0, CP_WINUNICODE))) WINE_ERR("DdeQueryString returned zero size of request string\n"); else if (!(ddeString = HeapAlloc(GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR)))) WINE_ERR("Out of memory\n"); else if (DdeQueryStringW(ddeInst, hsz2, ddeString, size + 1, CP_WINUNICODE) != size) WINE_WARN("DdeQueryString did not return %d characters\n", size); else ret = -2; /* acknowledgment */ return DdeCreateDataHandle(ddeInst, (LPBYTE)&ret, sizeof(ret), 0, hszReturn, CF_TEXT, 0); default: return NULL; } }
WString * WEXPORT WClient::sendMsg( const char *msg, WClientFlags flags ) { /*************************************************************************/ WString *reply = NULL; HSZ hsz = DdeCreateStringHandle( _procid, (char *)msg, CP_WINANSI ); HDDEDATA hdata = DdeClientTransaction( NULL, 0, _hconv, hsz, CF_TEXT, XTYP_REQUEST, _timeout, NULL ); DdeFreeStringHandle( _procid, hsz ); if( hdata != NULL && _timeout != TIMEOUT_ASYNC ) { int len = (int)DdeGetData( hdata, NULL, 0, 0 ); char *r = new char [len + 1]; DdeGetData( hdata, (unsigned char *)r, len, 0 ); DdeFreeDataHandle( hdata ); if( flags & CS_WANTREPLY ) { reply = new WString( r ); } delete[] r; } return( reply ); }
TEST_F(DataTest, testGetSize) {{ InSequence s; HDDEDATA hData = (HDDEDATA)11223; EXPECT_CALL(winApi, DdeGetData(hData, NULL, 0, 0)) .Times(1) .WillOnce(Return(15)); auto_drop<Data> data(new Data(&instance, &winApi, hData)); ASSERT_EQ(15, data->getSize()); }}
/*-------------------------------*/ void //------------------------------- /*module :: */ DDE_Data_Handle_To_String ( DWORD DDEIdentifier , HDDEDATA DataHdl , String& TargetString ) { //--- Get and validate data size --- DWORD Bytes = DdeGetData( DataHdl, NULL, 0, 0 ); if( DDE_Error( DDEIdentifier, "DDE_Data_Handle_To_String", "Retrieving data size." ) ) return ; assert( Bytes > 1 ); //--- Create string to hold data --- int String_Length = Bytes - 1; assert( String_Length > 0 ); TargetString.Redimension( String_Length ); // String String_Data( String_Length, "", ' ' ); //--- Get the data --- DdeGetData( DataHdl, (VOID_PTR)( (char*)( TargetString ) ), Bytes, 0 ); if( DDE_Error( DDEIdentifier, "DDE_Data_Handle_To_String", "Retrieving data from handle." ) ) return ; //--- Free the data handle DdeFreeDataHandle( DataHdl ); if( DDE_Error( DDEIdentifier, "DDE_Data_Handle_To_String", "Freeing the data handle." ) ) return ; return; }
HDDEDATA CALLBACK DdeCallback(UINT uType, UINT /*uFmt*/, HCONV /*hconv*/, HDDEDATA hsz1, HDDEDATA hsz2, HDDEDATA hdata, HDDEDATA /*dwData1*/, HDDEDATA /*dwData2*/) { switch (uType) { case XTYP_CONNECT: if(hsz2 == (HDDEDATA) g_serverName && hsz1 == (HDDEDATA) g_topic) return (HDDEDATA) 1; break; case XTYP_EXECUTE: { UINT size = DdeGetData(hdata, NULL, 0, 0); LPSTR execData = (LPSTR) malloc(size); DdeGetData(hdata, (LPBYTE) execData, size, 0); DDE::Execute(execData); free(execData); return (HDDEDATA) 1; } break; } return 0; }
TEST_F(DataTest, testGetData) {{ InSequence s; char buffer[256]; memset(buffer, 0, sizeof(buffer)); HDDEDATA hData = (HDDEDATA)88772; EXPECT_CALL(winApi, DdeGetData(hData, _, sizeof(buffer), 5)) .Times(1) .WillOnce(Invoke(this, &DataTest::DdeGetData)); auto_drop<Data> data(new Data(&instance, &winApi, hData)); ASSERT_EQ(8, data->getData((LPBYTE)buffer, sizeof(buffer), 5)); ASSERT_STREQ("zulu 19", buffer); }}
bool SleepyApi::Impl::IsPaused() const { if (!m_conv) return false; HDDEDATA res=DdeClientTransaction(NULL,0,m_conv,m_paused,CF_TEXT,XTYP_REQUEST,1000,NULL); if (!res) return false; char help[10]; DdeGetData(res,(LPBYTE)help,sizeof(help),0); DdeFreeDataHandle(res); return *help!='0'; }
void DDERequest(DWORD idInst, HCONV hConv, char* szItem, char* sDesc) { HSZ hszItem = DdeCreateStringHandle(idInst, szItem, 0); HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT, XTYP_ADVSTART/*XTYP_REQUEST*/, TIMEOUT_ASYNC/*5000*/ , NULL); if (hData==NULL) { printf("Request failed: %s\n", szItem); } else { char szResult[255]; DdeGetData(hData, (unsigned char *)szResult, 255, 0); printf("%s%s\n", sDesc, szResult); } }
char doRequest( char *szCommand ) { HDDEDATA hddeData; HSZ hszCommand; BYTE result; hszCommand = DdeCreateStringHandle( idInstance, szCommand, CP_WINANSI ); hddeData = DdeClientTransaction( NULL, 0, hConv, hszCommand, CF_TEXT, XTYP_REQUEST, 500000, NULL ); DdeFreeStringHandle( idInstance, hszCommand ); if( hddeData != (HDDEDATA)NULL ) { DdeGetData( hddeData, &result, 1, 0 ); DdeFreeDataHandle( hddeData ); return( result ); } return( 0 ); }
char *CDDEConnection::Request(const CString& item, int *size, int format) { DWORD result; HSZ atom = DDEGetAtom(item); HDDEDATA returned_data = DdeClientTransaction(NULL, 0, hConv, atom, format, XTYP_REQUEST, 5000, &result); DWORD len = DdeGetData(returned_data, (LPBYTE)(buf_ptr), buf_size, 0); DdeFreeDataHandle(returned_data); if (size) *size = (int)len; if (len > 0) { return buf_ptr; } else return NULL; }
//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; }
//-------------------- // BOOL DDEIntegratorClient::RecieveDataFromServer( char* pszDataName, char* pszBuffer, int nBufferLen ) { if (m_hConv == NULL) return FALSE; HSZ hszNameItem = DdeCreateStringHandle( gDDEClientId, (LPSTR)pszDataName, CP_WINANSI ); if ( hszNameItem == NULL ) return FALSE; m_dwDDEResult = 0; HDDEDATA hData = DdeClientTransaction( NULL, 0, m_hConv, hszNameItem, CF_TEXT, XTYP_REQUEST, DDE_IDECLIENT_TIMEOUT, &m_dwDDEResult); if ( hData ) { DdeGetData( hData, (UCHAR*)pszBuffer, nBufferLen, 0); DdeFreeDataHandle( hData ); } DdeFreeStringHandle( gDDEClientId, hszNameItem); return (BOOL)hData; }
HXBOOL BrowserOpenURL(const char* pszUrl, const char* pszTarget, const char* pszDefBrowser) { HX_TRACE("BrowserOpenURL()\r\n"); HXBOOL result = TRUE; DWORD dwResult = 0; HDDEDATA hOpenRetVal = NULL; HSZ hszOpenTopic = NULL; HSZ hszOpenItem = NULL; HCONV hOpenConv = NULL; HDDEDATA hActivateRetVal = NULL; HSZ hszActivateTopic = NULL; HSZ hszActivateItem = NULL; HCONV hActivateConv = NULL; UINT16 i = 0; UINT16 nNumberOfBrowsers = 0; char* pMessage = NULL; DWORD dwWindowID = 0xFFFFFFFF; // -1 = last active window DWORD dwLockTimeout = 0; HXBOOL bForceBroswserToForeground = FALSE; HXVERSIONINFO versionInfo; if (!pszUrl) { result = FALSE; goto cleanup; } pMessage = new char[strlen(pszUrl)+48]; if (!pMessage) { result = FALSE; goto cleanup; } // handle pszTarget parameter according to: // https://common.helixcommunity.org/nonav/2003/HCS_SDK_r5/htmfiles/HyperNavigate.htm if (pszTarget && (0 == strcmp(pszTarget, "_new") || 0 == strcmp(pszTarget, "_blank"))) { dwWindowID = 0; } ZeroInit(&versionInfo); HXGetWinVer(&versionInfo); bForceBroswserToForeground = ((versionInfo.dwPlatformId == HX_PLATFORM_WIN98) || (versionInfo.dwPlatformId == HX_PLATFORM_WINNT && versionInfo.wMajorVersion > 4)); DDEStartup(); // establish browser if (NULL == g_hszWWWService) { hszOpenTopic = DdeCreateStringHandle(g_dwIdInst, "WWW_OpenURL", CP_WINANSI); if (hszOpenTopic) { nNumberOfBrowsers = sizeof(g_BrowsersSupportingDDE)/sizeof(DDE_Browsers); // Look for a browser that supports DDE??? while (i < nNumberOfBrowsers) { g_hszWWWService = DdeCreateStringHandle(g_dwIdInst, g_BrowsersSupportingDDE[i].szDDEName, CP_WINANSI); hOpenConv = DdeConnect(g_dwIdInst, g_hszWWWService, hszOpenTopic, NULL); if (hOpenConv) { break; } if(g_hszWWWService) { DdeFreeStringHandle(g_dwIdInst, g_hszWWWService); g_hszWWWService = NULL; } i++; } } if (NULL == g_hszWWWService) { result = FALSE; goto cleanup; } } else { hszOpenTopic = DdeCreateStringHandle(g_dwIdInst,"WWW_OpenURL", CP_WINANSI); hOpenConv = DdeConnect(g_dwIdInst, g_hszWWWService, hszOpenTopic, NULL); } if (!hOpenConv) { HX_TRACE("Conversation failed to start...\r\n"); DdeFreeStringHandle(g_dwIdInst, g_hszWWWService); g_hszWWWService = NULL; result = FALSE; goto cleanup; } wsprintf(pMessage,"\"%s\",,%lu,0,,,,", pszUrl, dwWindowID); hszOpenItem = DdeCreateStringHandle(g_dwIdInst, pMessage, CP_WINANSI); HX_TRACE("Conversation started, sending URL command...\r\n"); // Request hOpenRetVal = DdeClientTransaction(NULL, 0, hOpenConv, hszOpenItem, CF_TEXT, XTYP_REQUEST, 60000, NULL); if (DDE_FNOTPROCESSED != hOpenRetVal) { DdeGetData(hOpenRetVal, (LPBYTE)&dwResult, sizeof(dwResult), 0); if (!dwResult) { result = FALSE; goto cleanup; } } // force the browser to the foreground then do it here. This does not actually put the browser // in the foreground instead it enables the browser's call to SetForegroundWindow to bring the window to the // front instead of flashing it on the taskbar if (bForceBroswserToForeground) { // These are new flags that work on Win98 and WinNT5 ONLY. First get the current foreground lock timeout and save // it off and then set it to 0. ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&dwLockTimeout,0); ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,0); } // activate the browser wsprintf(pMessage, "%lu,0", dwWindowID); hszActivateItem = DdeCreateStringHandle(g_dwIdInst, pMessage, CP_WINANSI); hszActivateTopic = DdeCreateStringHandle(g_dwIdInst,"WWW_Activate", CP_WINANSI); // Connect to server if (hszActivateTopic && hszActivateItem) { hActivateConv = DdeConnect(g_dwIdInst, g_hszWWWService, hszActivateTopic, NULL); if (hActivateConv) { hActivateRetVal = DdeClientTransaction(NULL, 0, hActivateConv, hszActivateItem, CF_TEXT, XTYP_REQUEST, 10000, NULL); } } if (bForceBroswserToForeground) { // Restore the old foreground lock timeout ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)dwLockTimeout,0); } cleanup: if (hOpenRetVal) DdeFreeDataHandle(hOpenRetVal); if (hActivateRetVal) DdeFreeDataHandle(hActivateRetVal); if (hszOpenTopic) DdeFreeStringHandle(g_dwIdInst, hszOpenTopic); if (hszActivateTopic) DdeFreeStringHandle(g_dwIdInst, hszActivateTopic); if (hszOpenItem) DdeFreeStringHandle(g_dwIdInst, hszOpenItem); if (hszActivateItem) DdeFreeStringHandle(g_dwIdInst, hszActivateItem); if (hOpenConv) DdeDisconnect(hOpenConv); if (hActivateConv) DdeDisconnect(hActivateConv); HX_VECTOR_DELETE(pMessage); DDEShutdown(); return result; }
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; }
UINT GetSize() { return DdeGetData(m_hdata, NULL, 0, 0); }
/***************************************************************** * DdeGetData [DDEML.16] */ DWORD WINAPI DdeGetData16(HDDEDATA hData, LPBYTE pDst, DWORD cbMax, DWORD cbOff) { return DdeGetData(hData, pDst, cbMax, cbOff); }
UINT GetData(byte* dst, UINT cb, UINT offset = 0) { return DdeGetData(m_hdata, dst, cb, offset); }
HDDEDATA FAR PASCAL _export PowDdeServerProc (UINT type,UINT fmt,HCONV hconv,HSZ hsz1,HSZ hsz2,HDDEDATA hdata,DWORD dwData1,DWORD dwData2) { LPSTR exec; HWND hWnd; DWORD size; HDDEDATA hDat; switch (type) { case XTYP_CONNECT: return (HDDEDATA)IsTopic(hsz1); case XTYP_EXECUTE: { char buf[1000]; if (IsTopic(hsz1)) { DdeGetData(hdata,buf,sizeof(buf),0); exec=GetExecData(buf); if (IsCommand(buf,"openfile")) { if (*exec && (hWnd=AlreadyOpen(exec))) BringWindowToTop(hWnd); else { #ifndef _WIN32 DownStr(exec); #endif AddFile(exec); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"newfile")) { hWnd=AddFile(0); if (hWnd && *exec) { HWND old; if (old=AlreadyOpen(exec)) SendMessage (hwndMDIClient,WM_MDIDESTROY,(WPARAM)old,0L); #ifndef _WIN32 DownStr(exec); #endif SetWindowText(hWnd,exec); SetWindowWord(hWnd,GWW_UNTITLED,0); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"savefile")) { if (GetActiveEditWindow(hwndMDIClient)) { if (*exec) { #ifndef _WIN32 AnsiLower(exec); #endif SetWindowText(GetActiveEditWindow(hwndMDIClient),exec); SetWindowWord(GetActiveEditWindow(hwndMDIClient),GWW_UNTITLED,0); } SendMessage(hwndFrame,WM_COMMAND,IDM_FILESAVE,0); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"activate")) { if (*exec && (hWnd=AlreadyOpen(exec))) BringWindowToTop(hWnd); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"appendtext") || IsCommand(buf,"addtext")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) EditAddText(GetActiveEditWindow(hwndMDIClient),exec); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"inserttext")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) EditInsertText(GetActiveEditWindow(hwndMDIClient),exec); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"appendfile") || IsCommand(buf,"addtext")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { EditGotoPos(GetActiveEditWindow(hwndMDIClient),-1,-1); InsertFile(exec); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"insertfile")) { if (*exec && GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) InsertFile(exec); return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"showposition")) { /* go to line/col of a given file (open if necessary) */ if (*exec) { char *file,*sline,*scol; int line=-1,col=-1; file=strtok(exec," "); if (file) { /* read position */ sline=strtok(NULL," "); if (sline) { line=atoi(sline); scol=strtok(NULL," "); if (scol) col=atoi(scol); } /* display the file */ if (hWnd=AlreadyOpen(file)) BringWindowToTop(hWnd); else { #ifndef _WIN32 DownStr(file); #endif AddFile(file); } /* set caret to given position */ EditGotoPos(GetActiveEditWindow(hwndMDIClient),line,col); } } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"addtool")) { /* create a new tool */ if (*exec) { LPSTR lp; char *name,*cmd,*dir,*options; BOOL menu,askArg,toTop; int buttonId; name=cmd=dir=options=NULL; menu=askArg=toTop=FALSE; buttonId=0; /* read tool name */ name=strtok(exec,","); if (name) { cmd=strtok(NULL,","); if (cmd) { dir=strtok(NULL,","); if (dir) { options=strtok(NULL,","); if (options) { lp=strtok(NULL,","); if (lp) { menu=(BOOL)atoi(lp); lp=strtok(NULL,","); if (lp) { buttonId=atoi(lp); lp=strtok(NULL,","); if (lp) { toTop=(BOOL)atoi(lp); lp=strtok(NULL,","); if (lp) { askArg=(BOOL)atoi(lp); } } } } } } } } if (strcmp(dir," ")==0) dir=""; if (strcmp(options," ")==0) options=""; if (name && cmd && *name && *cmd && (menu || buttonId)) ToolAdd(name,cmd,dir,options,menu,buttonId,toTop,askArg); } return (HDDEDATA)DDE_FACK; } else if (IsCommand(buf,"deletetool")) { /* remove an external tool */ if (*exec) ToolDelete(exec); return (HDDEDATA)DDE_FACK; } } return (HDDEDATA)DDE_FNOTPROCESSED; } case XTYP_POKE: { if (IsTopic(hsz1)) { if (IsEqualString(hsz2,"editbuffer")) { if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { LPSTR lBuf; if (lBuf=DdeAccessData(hdata,(LPDWORD)&size)) { EditResetContent(GetActiveEditWindow(hwndMDIClient)); EditAddText(GetActiveEditWindow(hwndMDIClient),lBuf); DdeUnaccessData(hdata); } } return (HDDEDATA)DDE_FACK; } } return (HDDEDATA)DDE_FNOTPROCESSED; } case XTYP_REQUEST: { if (IsTopic(hsz1)) { if (IsEqualString(hsz2,"activefile")) { if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { long len; char name[100]; HSZ hitem; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"activefile",CP_WINANSI); len=GetWindowText(GetActiveEditWindow(hwndMDIClient),(LPSTR)name,sizeof(name)); return DdeCreateDataHandle(ddeInstId,(LPSTR)name,len+1,0,hitem,CF_TEXT,0); } } else if (IsEqualString(hsz2,"editbuffer")) { if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient))) { LPSTR lp; HGLOBAL h; if (h=EditGetText(GetActiveEditWindow(hwndMDIClient))) { HSZ hitem; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"editbuffer",CP_WINANSI); lp=GlobalLock(h); hDat=DdeCreateDataHandle(ddeInstId,lp,GlobalSize(h),0,hitem,CF_TEXT,0); GlobalUnlock(h); GlobalFree(h); } else hDat=0; return hDat; } } else if (IsEqualString(hsz2,"compiler")) { /* return name of active compiler interface dll */ char name[100]; HSZ hitem; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"compiler",CP_WINANSI); strcpy(name,actConfig.compiler); return DdeCreateDataHandle(ddeInstId,(LPSTR)name,strlen(name)+1,0,hitem,CF_TEXT,0); } else if (IsEqualString(hsz2,"executable")) { /* return name of target executale */ BOOL isExecutable; //FARPROC lpfn; char name[500]; HSZ hitem; if (IsCompilerInterfaceLoaded()) { if (!*actPrj) { RemoveMessageWindow(); if (GetActiveEditWindow(hwndMDIClient) && IsEditWindow(GetActiveEditWindow(hwndMDIClient)) && !GetWindowWord(GetActiveEditWindow(hwndMDIClient),GWW_UNTITLED)) { SetDefaultProjectName(); isExecutable=(*compGetTarget)(hCompData,(LPSTR)name); if (*name && *RunArgs) { /* append run arguments (as string included in "") */ strcat(name," \""); strcat(name,RunArgs); strcat(name,"\""); } } else *name=0; } else isExecutable=(*compGetTarget)(hCompData,(LPSTR)name); } else *name=0; hitem=DdeCreateStringHandle(ddeInstId,(LPSTR)"executable",CP_WINANSI); return DdeCreateDataHandle(ddeInstId,(LPSTR)name,strlen(name)+1,0,hitem,CF_TEXT,0); } } return (HDDEDATA) NULL; } } if (type&XCLASS_FLAGS) return (HDDEDATA)DDE_FNOTPROCESSED; else return (HDDEDATA)NULL; }
/***************************************************************************\ * DoCallback * * Description: * Performs a synchronous callback to the given instance's callback proc. * * History: * 11-12-91 sanfords Created. \***************************************************************************/ HDDEDATA DoCallback( PCL_INSTANCE_INFO pcii, WORD wType, WORD wFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dw1, DWORD dw2) { HDDEDATA hDataRet; PCLIENTINFO pci; CheckDDECritIn; /* * Zombie conversations don't generate callbacks! */ if (hConv && TypeFromHandle(hConv) == HTYPE_ZOMBIE_CONVERSATION) { return(0); } pci = GetClientInfo(); pci->cInDDEMLCallback++; pcii->cInDDEMLCallback++; pci->hDdemlCallbackInst = pcii->hInstClient; LeaveDDECrit; CheckDDECritOut; hDataRet = (*pcii->pfnCallback)((UINT)wType, (UINT)wFmt, hConv, hsz1, hsz2, hData, dw1, dw2); EnterDDECrit; pcii->cInDDEMLCallback--; pci->cInDDEMLCallback--; if (!(pcii->afCmd & APPCLASS_MONITOR) && pcii->MonitorFlags & MF_CALLBACKS) { PEVENT_PACKET pep; pep = (PEVENT_PACKET)DDEMLAlloc(sizeof(EVENT_PACKET) - sizeof(DWORD) + sizeof(MONCBSTRUCT)); if (pep != NULL) { pep->EventType = MF_CALLBACKS; pep->fSense = TRUE; pep->cbEventData = sizeof(MONCBSTRUCT); #define pcbs ((MONCBSTRUCT *)&pep->Data) pcbs->cb = sizeof(MONCBSTRUCT); pcbs->dwTime = NtGetTickCount(); pcbs->hTask = (HANDLE)pcii->tid; pcbs->dwRet = (DWORD)hDataRet; pcbs->wType = wType; pcbs->wFmt = wFmt; pcbs->hConv = hConv; pcbs->hsz1 = (HSZ)LocalToGlobalAtom(LATOM_FROM_HSZ(hsz1)); pcbs->hsz2 = (HSZ)LocalToGlobalAtom(LATOM_FROM_HSZ(hsz2)); pcbs->hData = hData; pcbs->dwData1 = dw1; pcbs->dwData2 = dw2; if (((wType == XTYP_CONNECT) || (wType == XTYP_WILDCONNECT)) && dw1) { RtlCopyMemory(&pcbs->cc, (PVOID)dw1, sizeof(CONVCONTEXT)); } LeaveDDECrit; if (wType & XCLASS_DATA) { if (hDataRet && hDataRet != CBR_BLOCK) { pcbs->cbData = DdeGetData(hDataRet, (LPBYTE)pcbs->Data, 32, 0); } } else if (hData) { pcbs->cbData = DdeGetData(hData, (LPBYTE)pcbs->Data, 32, 0); } Event(pep); EnterDDECrit; GlobalDeleteAtom(LATOM_FROM_HSZ(pcbs->hsz1)); GlobalDeleteAtom(LATOM_FROM_HSZ(pcbs->hsz2)); DDEMLFree(pep); #undef pcbs } } return (hDataRet); }
bool WdeStartDDEEditSession( void ) { WdeResInfo *rinfo; WdeResDlgItem *ditem; char *filename; HDDEDATA hData; void *data; DWORD ret; uint_32 size; OBJPTR object; bool ok; object = NULL; ditem = WdeAllocResDlgItem(); ok = (ditem != NULL); if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hFileItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); ok = (hData != (HDDEDATA)NULL); } if( ok ) { filename = (char *)WdeHData2Mem( hData ); DdeFreeDataHandle( hData ); ok = (filename != NULL); } if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hIs32BitItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); if( hData != (HDDEDATA)NULL ) { ditem->is32bit = TRUE; DdeFreeDataHandle( hData ); } } if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hNameItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); ok = (hData != (HDDEDATA)NULL); } if( ok ) { data = WdeHData2Mem( hData ); DdeFreeDataHandle( hData ); ok = (data != NULL); } if( ok ) { ditem->dialog_name = WRMem2WResID( data, ditem->is32bit ); ok = (ditem->dialog_name != NULL); WRMemFree( data ); } if( ok ) { hData = DdeClientTransaction( NULL, 0, WdeClientConv, hDataItem, WdeDataClipbdFormat, XTYP_REQUEST, TIME_OUT, &ret ); if( hData != (HDDEDATA)NULL ) { data = WdeHData2Mem( hData ); size = (int)DdeGetData( hData, NULL, 0, 0 ); DdeFreeDataHandle( hData ); if( data != NULL ) { ditem->dialog_info = WdeMem2DBI( (uint_8 *)data, size, ditem->is32bit ); ok = (ditem->dialog_info != NULL); WRMemFree( data ); } else { ok = false; } } } if( ok ) { rinfo = WdeCreateNewResource( filename ); ok = (rinfo != NULL); } if( ok ) { if( ditem->dialog_info != NULL ) { ok = WdeOpenDialogFromResInfo( rinfo, ditem ); if( ok ) { WdeAddResDlgItemToResInfo( rinfo, ditem ); object = ditem->object; } } else { object = WdeCreateNewDialog( ditem->dialog_name, ditem->is32bit ); if( ditem != NULL ) { WdeFreeResDlgItem( &ditem, TRUE ); } ditem = NULL; } ok = ok && (object != NULL); } if( ok ) { MakeObjectCurrent( object ); } if( !ok ) { if( ditem != NULL ) { WdeFreeResDlgItem( &ditem, TRUE ); } if( rinfo != NULL ) { WdeFreeResInfo( rinfo ); } } if( filename != NULL ) { WRMemFree( filename ); } return( ok ); }
HDDEDATA gcDDEConnection::handlePoke(HSZ hszItem, HDDEDATA hData) { char item_name[255]; GetDDEManager()->stringFromAtom(hszItem, item_name, 255); if (!hData) { onPoke(item_name, nullptr, 0); return (HDDEDATA)DDE_FACK; } DWORD len = DdeGetData(hData, nullptr, 0, 0); if (len == 0) { onPoke(item_name, nullptr, 0); return (HDDEDATA)DDE_FACK; } char *data = new char[len+1]; DdeGetData(hData, (LPBYTE)data, len, 0); data[len] = '\0'; DdeFreeDataHandle(hData); if (len > 0) { int x = len-1; while ( x+1 ) { if (data[x] == '\r' || data[x] == '\n') { data[x] = '\0'; len--; } else { break; } x--; } } char f = data[0]; char l = data[len-1]; //if it has " " around it remove them if (f == 34 && l == 34) { for (size_t x=0; x<(len-2); x++) { data[x]=data[x+1]; } data[len-2]='\0'; } size_t size = strlen((char*)data); onPoke(item_name, (char*)data, size); safe_delete(data); return (HDDEDATA)DDE_FACK; }