/****************************************************************** * WDML_HandleIncomingData * * */ static WDML_QUEUE_STATE WDML_HandleIncomingData(WDML_CONV* pConv, MSG* msg, HDDEDATA* hdd) { UINT_PTR uiLo, uiHi; HDDEDATA hDdeDataIn, hDdeDataOut; WDML_LINK* pLink; WINE_DDEHEAD wdh; HSZ hsz; TRACE("WM_DDE_DATA message received in the Client Proc!\n"); /* wParam -- sending window handle */ /* lParam -- hDdeData & item HSZ */ UnpackDDElParam(WM_DDE_DATA, msg->lParam, &uiLo, &uiHi); hsz = WDML_MakeHszFromAtom(pConv->instance, uiHi); hDdeDataIn = WDML_Global2DataHandle(pConv, (HGLOBAL)uiLo, &wdh); /* billx: * For hot link, data should be passed to its callback with * XTYP_ADVDATA and callback should return the proper status. */ pLink = WDML_FindLink(pConv->instance, (HCONV)pConv, WDML_CLIENT_SIDE, hsz, uiLo != 0, wdh.cfFormat); if (!pLink) { WDML_DecHSZ(pConv->instance, hsz); DdeFreeDataHandle(hDdeDataIn); return WDML_QS_PASS; } if (hDdeDataIn != 0 && wdh.fAckReq) { WDML_PostAck(pConv, WDML_CLIENT_SIDE, 0, FALSE, TRUE, uiHi, msg->lParam, WM_DDE_DATA); if (msg->lParam) msg->lParam = 0; } else { GlobalDeleteAtom(uiHi); } hDdeDataOut = WDML_InvokeCallback(pConv->instance, XTYP_ADVDATA, pLink->uFmt, pLink->hConv, pConv->hszTopic, pLink->hszItem, hDdeDataIn, 0, 0); if (hDdeDataOut != (HDDEDATA)DDE_FACK || wdh.fRelease) { if (uiLo) GlobalFree((HANDLE)uiLo); } DdeFreeDataHandle(hDdeDataIn); WDML_DecHSZ(pConv->instance, hsz); if (msg->lParam) FreeDDElParam(WM_DDE_DATA, msg->lParam); return WDML_QS_HANDLED; }
bool WdeUpdateDDEEditSession( void ) { WdeResInfo *rinfo; WdeResDlgItem *ditem; HDDEDATA hdata; bool ok; hdata = (HDDEDATA)NULL; ditem = WdeGetDlgItem(); ok = (WdeClientConv != (HCONV)NULL && ditem != NULL); if( ok ) { hdata = WdeCreateResData( ditem ); ok = (hdata != (HDDEDATA)NULL); } if( ok ) { ok = DdeClientTransaction( (LPBYTE)hdata, -1, WdeClientConv, hDataItem, WdeDataClipbdFormat, XTYP_POKE, TIME_OUT, NULL ) != 0; } if( hdata != (HDDEDATA)NULL ) { DdeFreeDataHandle( hdata ); } if( ok ) { hdata = WdeCreateResNameData( ditem->dialog_name, ditem->is32bit ); ok = (hdata != (HDDEDATA)NULL); } if( ok ) { ok = DdeClientTransaction( (LPBYTE)hdata, -1, WdeClientConv, hNameItem, WdeDataClipbdFormat, XTYP_POKE, TIME_OUT, NULL ) != 0; } if( hdata != (HDDEDATA)NULL ) { DdeFreeDataHandle( hdata ); } if( ok ) { rinfo = WdeGetCurrentRes(); WdeSetResModified( rinfo, FALSE ); } return( ok ); }
/* * IEUpdateDDEEditSession */ BOOL IEUpdateDDEEditSession( void ) { img_node *node; HDDEDATA hdata; BOOL ok; hdata = (HDDEDATA)NULL; node = IEGetCurrentImageNode(); ok = (IEClientConv != (HCONV)NULL && node != NULL && EditFormat != DDENone); if( ok ) { hdata = IECreateResData( node ); ok = (hdata != (HDDEDATA)NULL); } if( ok ) { ok = DdeClientTransaction( (LPBYTE)hdata, -1, IEClientConv, hDataItem, IEClipFormats[EditFormat].format, XTYP_POKE, TIME_OUT, NULL ) != 0; } if( hdata != (HDDEDATA)NULL ) { DdeFreeDataHandle( hdata ); } if( ok ) { SetIsSaved( node->hwnd, TRUE ); } return( ok ); } /* IEUpdateDDEEditSession */
JNIEXPORT jbyteArray JNICALL Java_com_google_code_jdde_ddeml_DdeAPI_ClientTransaction (JNIEnv *env, jclass cls, jint idInst, jbyteArray jpData, jint hConv, jstring jhszItem, jint wFmt, jint wType, jint dwTimeout, jobject $dwResult) { HSZ hszItem = UtilCreateStringHandle(env, idInst, jhszItem); HDDEDATA pData = NULL; DWORD dwResult = 0; if (jpData != NULL) { jsize cb = env->GetArrayLength(jpData); jbyte *pSrc = env->GetByteArrayElements(jpData, 0); pData = DdeCreateDataHandle(idInst, (LPBYTE) pSrc, cb, 0, hszItem, wFmt, 0); env->ReleaseByteArrayElements(jpData, pSrc, 0); } HDDEDATA hddeData = DdeClientTransaction( (LPBYTE) pData, 0xFFFFFFFF, (HCONV) hConv, hszItem, wFmt, wType, dwTimeout, &dwResult ); if (pData != NULL) { DdeFreeDataHandle(pData); } UtilFreeStringHandle(idInst, hszItem); if ($dwResult != NULL) { SetObjectInPointer(env, $dwResult, NewInteger(env, dwResult)); } if (hddeData == NULL) { return NULL; } else if (wType == XTYP_REQUEST) { jbyteArray result = ExtractData(env, hddeData); DdeFreeDataHandle(hddeData); return result; } return env->NewByteArray(0); }
~DdeDataHandle() { if (m_hdata) { DdeFreeDataHandle(m_hdata); m_hdata = NULL; } }
void DDEExecute(const WCHAR* server, const WCHAR* topic, const WCHAR* command) { unsigned long inst = 0; HSZ hszServer = NULL, hszTopic = NULL; HCONV hconv = NULL; HDDEDATA hddedata = NULL; #ifdef _WIN64 CrashIf(str::Len(command) >= (DWORD)-1); if (str::Len(command) >= (DWORD)-1) return; #endif UINT result = DdeInitialize(&inst, &DdeCallback, APPCMD_CLIENTONLY, 0); if (result != DMLERR_NO_ERROR) goto Exit; hszServer = DdeCreateStringHandle(inst, server, CP_WINNEUTRAL); if (!hszServer) goto Exit; hszTopic = DdeCreateStringHandle(inst, topic, CP_WINNEUTRAL); if (!hszTopic) goto Exit; hconv = DdeConnect(inst, hszServer, hszTopic, 0); if (!hconv) goto Exit; DWORD cbLen = ((DWORD)str::Len(command) + 1) * sizeof(WCHAR); hddedata = DdeCreateDataHandle(inst, (BYTE*)command, cbLen, 0, 0, CF_UNICODETEXT, 0); if (!hddedata) goto Exit; HDDEDATA answer = DdeClientTransaction((BYTE*)hddedata, (DWORD)-1, hconv, 0, 0, XTYP_EXECUTE, 10000, 0); if (answer) DdeFreeDataHandle(answer); Exit: if (hddedata) DdeFreeDataHandle(hddedata); if (hconv) DdeDisconnect(hconv); if (hszTopic) DdeFreeStringHandle(inst, hszTopic); if (hszServer) DdeFreeStringHandle(inst, hszServer); DdeUninitialize(inst); }
/****************************************************************** * WDML_ServerHandlePoke * * */ static WDML_QUEUE_STATE WDML_ServerHandlePoke(WDML_CONV* pConv, WDML_XACT* pXAct) { DDEPOKE* pDdePoke; HDDEDATA hDdeData; BOOL fBusy = FALSE, fAck = FALSE; pDdePoke = (DDEPOKE*)GlobalLock(pXAct->hMem); if (!pDdePoke) { return WDML_QS_ERROR; } if (!(pConv->instance->CBFflags & CBF_FAIL_POKES)) { hDdeData = DdeCreateDataHandle(pConv->instance->instanceID, pDdePoke->Value, GlobalSize(pXAct->hMem) - sizeof(DDEPOKE) + 1, 0, 0, pDdePoke->cfFormat, 0); if (hDdeData) { HDDEDATA hDdeDataOut; hDdeDataOut = WDML_InvokeCallback(pConv->instance, XTYP_POKE, pDdePoke->cfFormat, (HCONV)pConv, pConv->hszTopic, pXAct->hszItem, hDdeData, 0, 0); switch ((UINT)hDdeDataOut) { case DDE_FACK: fAck = TRUE; break; case DDE_FBUSY: fBusy = TRUE; break; default: FIXME("Unsupported returned value %08lx\n", (DWORD)hDdeDataOut); /* fal through */ case DDE_FNOTPROCESSED: break; } DdeFreeDataHandle(hDdeData); } } GlobalUnlock(pXAct->hMem); if (!fAck) { GlobalFree(pXAct->hMem); } WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, fBusy, fAck, pXAct->atom, pXAct->lParam, WM_DDE_POKE); WDML_DecHSZ(pConv->instance, pXAct->hszItem); return WDML_QS_HANDLED; }
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'; }
CConv::~CConv() { if(hConv) { // char note_remove_msg_box; // AfxMessageBox("attempting disconnect"); DdeDisconnect(hConv); } #ifdef WIN32 if(ret) { DdeFreeDataHandle(ret); //AE:5/22/96 causing GPF under win31. Apparently because these //are asynchronous transactions, there really isn't a valid data //handle returned. ret = NULL; } #endif }
/****************************************************************** * WDML_ServerHandleRequest * * */ static WDML_QUEUE_STATE WDML_ServerHandleRequest(WDML_CONV* pConv, WDML_XACT* pXAct) { HDDEDATA hDdeData = 0; BOOL fAck = TRUE; if (!(pConv->instance->CBFflags & CBF_FAIL_REQUESTS)) { hDdeData = WDML_InvokeCallback(pConv->instance, XTYP_REQUEST, pXAct->wFmt, (HCONV)pConv, pConv->hszTopic, pXAct->hszItem, 0, 0, 0); } switch ((ULONG_PTR)hDdeData) { case 0: TRACE("No data returned from the Callback\n"); fAck = FALSE; break; case (ULONG_PTR)CBR_BLOCK: return WDML_QS_BLOCK; default: { HGLOBAL hMem = WDML_DataHandle2Global(hDdeData, TRUE, FALSE, FALSE, FALSE); if (!PostMessageW(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer, ReuseDDElParam(pXAct->lParam, WM_DDE_REQUEST, WM_DDE_DATA, (UINT_PTR)hMem, (UINT_PTR)pXAct->atom))) { pConv->instance->lastError = DMLERR_POSTMSG_FAILED; DdeFreeDataHandle(hDdeData); GlobalFree(hMem); fAck = FALSE; } } break; } WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, FALSE, fAck, pXAct->atom, pXAct->lParam, WM_DDE_REQUEST); WDML_DecHSZ(pConv->instance, pXAct->hszItem); return WDML_QS_HANDLED; }
/* 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; } }
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 ); }
bool DDEExecute(const WCHAR* server, const WCHAR* topic, const WCHAR* command) { DWORD inst = 0; HSZ hszServer = NULL, hszTopic = NULL; HCONV hconv = NULL; bool ok = false; CrashIf(str::Len(command) >= INT_MAX - 1); if (str::Len(command) >= INT_MAX - 1) return false; UINT result = DdeInitialize(&inst, DdeCallback, APPCMD_CLIENTONLY, 0); if (result != DMLERR_NO_ERROR) return false; hszServer = DdeCreateStringHandle(inst, server, CP_WINNEUTRAL); if (!hszServer) goto Exit; hszTopic = DdeCreateStringHandle(inst, topic, CP_WINNEUTRAL); if (!hszTopic) goto Exit; hconv = DdeConnect(inst, hszServer, hszTopic, NULL); if (!hconv) goto Exit; DWORD cbLen = ((DWORD)str::Len(command) + 1) * sizeof(WCHAR); HDDEDATA answer = DdeClientTransaction((BYTE *)command, cbLen, hconv, 0, CF_UNICODETEXT, XTYP_EXECUTE, 10000, NULL); if (answer) { DdeFreeDataHandle(answer); ok = true; } Exit: if (hconv) DdeDisconnect(hconv); if (hszTopic) DdeFreeStringHandle(inst, hszTopic); if (hszServer) DdeFreeStringHandle(inst, hszServer); DdeUninitialize(inst); return ok; }
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; }
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 ); }
//-------------------- // BOOL DDEIntegratorClient::SendDataToServer( char* pszDataName, char* pszData ) { if (m_hConv == NULL) return FALSE; HSZ hszNameItem = DdeCreateStringHandle( gDDEClientId, (LPSTR)pszDataName, CP_WINANSI ); if ( hszNameItem == NULL ) return FALSE; HDDEDATA hData = DdeCreateDataHandle( gDDEClientId, (UCHAR*)pszData, strlen(pszData)+1, 0L, hszNameItem, CF_TEXT, 0); if ( hData ) HDDEDATA hDataT= DdeClientTransaction( (UCHAR*)hData, (ULONG)-1L, m_hConv, hszNameItem, CF_TEXT, XTYP_POKE, DDE_IDECLIENT_TIMEOUT, NULL); DdeFreeDataHandle (hData ); DdeFreeStringHandle( gDDEClientId, hszNameItem); return (BOOL)hData; }
/*-------------------------------*/ 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; }
//-------------------- // 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; }
/**************************************************************************** * * * 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; }
/* 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); }
/****************************************************************** * WDML_ServerHandleRequest * * */ static WDML_QUEUE_STATE WDML_ServerHandleRequest(WDML_CONV* pConv, WDML_XACT* pXAct) { HDDEDATA hDdeData = 0; WDML_QUEUE_STATE ret = WDML_QS_HANDLED; if (!(pConv->instance->CBFflags & CBF_FAIL_REQUESTS)) { hDdeData = WDML_InvokeCallback(pConv->instance, XTYP_REQUEST, pXAct->wFmt, (HCONV)pConv, pConv->hszTopic, pXAct->hszItem, 0, 0, 0); } switch ((DWORD)hDdeData) { case 0: WDML_PostAck(pConv, WDML_SERVER_SIDE, 0, FALSE, FALSE, pXAct->atom, pXAct->lParam, WM_DDE_REQUEST); break; case CBR_BLOCK: ret = WDML_QS_BLOCK; break; default: { HGLOBAL hMem = WDML_DataHandle2Global(hDdeData, FALSE, FALSE, FALSE, FALSE); if (!PostMessageA(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer, ReuseDDElParam(pXAct->lParam, WM_DDE_REQUEST, WM_DDE_DATA, (UINT)hMem, (UINT)pXAct->atom))) { DdeFreeDataHandle(hDdeData); GlobalFree(hMem); } } break; } WDML_DecHSZ(pConv->instance, pXAct->hszItem); return ret; }
/****************************************************************************** * DdePostAdvise [USER32.@] Send transaction to DDE callback function. * * PARAMS * idInst [I] Instance identifier * hszTopic [I] Handle to topic name string * hszItem [I] Handle to item name string * * RETURNS * Success: TRUE * Failure: FALSE */ BOOL WINAPI DdePostAdvise(DWORD idInst, HSZ hszTopic, HSZ hszItem) { WDML_INSTANCE* pInstance = NULL; WDML_LINK* pLink = NULL; HDDEDATA hDdeData = 0; HGLOBAL hItemData = 0; WDML_CONV* pConv = NULL; ATOM atom = 0; UINT count; TRACE("(%ld,0x%x,0x%x)\n", idInst, hszTopic, hszItem); EnterCriticalSection(&WDML_CritSect); pInstance = WDML_GetInstance(idInst); if (pInstance == NULL || pInstance->links == NULL) { goto theError; } atom = WDML_MakeAtomFromHsz(hszItem); if (!atom) goto theError; /* first compute the number of links which will trigger a message */ count = 0; for (pLink = pInstance->links[WDML_SERVER_SIDE]; pLink != NULL; pLink = pLink->next) { if (DdeCmpStringHandles(hszItem, pLink->hszItem) == 0) { count++; } } if (count >= CADV_LATEACK) { FIXME("too high value for count\n"); count &= 0xFFFF; } for (pLink = pInstance->links[WDML_SERVER_SIDE]; pLink != NULL; pLink = pLink->next) { if (DdeCmpStringHandles(hszItem, pLink->hszItem) == 0) { hDdeData = WDML_InvokeCallback(pInstance, XTYP_ADVREQ, pLink->uFmt, pLink->hConv, hszTopic, hszItem, 0, count--, 0); if (hDdeData == (HDDEDATA)CBR_BLOCK) { /* MS doc is not consistent here */ FIXME("CBR_BLOCK returned for ADVREQ\n"); continue; } if (hDdeData) { if (pLink->transactionType & XTYPF_NODATA) { TRACE("no data\n"); hItemData = 0; } else { TRACE("with data\n"); hItemData = WDML_DataHandle2Global(hDdeData, FALSE, FALSE, FALSE, FALSE); } pConv = WDML_GetConv(pLink->hConv, TRUE); if (pConv == NULL) { if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData); goto theError; } if (!PostMessageA(pConv->hwndClient, WM_DDE_DATA, (WPARAM)pConv->hwndServer, PackDDElParam(WM_DDE_DATA, (UINT)hItemData, atom))) { ERR("post message failed\n"); pConv->wStatus &= ~ST_CONNECTED; if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData); GlobalFree(hItemData); goto theError; } if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData); } } } LeaveCriticalSection(&WDML_CritSect); return TRUE; theError: LeaveCriticalSection(&WDML_CritSect); if (atom) GlobalDeleteAtom(atom); return FALSE; }
int gsview_progman(char *groupname, char *gsviewpath, int gsver, char *gspath, char *gsargs) { DWORD idInst = 0L; FARPROC lpDdeProc; HSZ hszServName; HSZ hszSysTopic; HSZ hszGroupsItem; HCONV hConv; HDDEDATA hdata = NULL; char setup[MAXSTR+MAXSTR]; DWORD dwResult; char groupfile[MAXSTR]; int i; char *s, *d; FILE *ddefile; char gspathbuf[MAXSTR]; char gsviewpathbuf[MAXSTR]; char gsdocbuf[MAXSTR]; strncpy(gspathbuf, gspath, sizeof(gspathbuf)/sizeof(TCHAR)); strncpy(gsdocbuf, gsargs, sizeof(gsdocbuf)/sizeof(TCHAR)); d = strchr(gsdocbuf, ';'); if (d) *d = '\0'; if (gsver >= 593) { d = strrchr(gsdocbuf, '\\'); if (d) { d++; strcpy(d, "doc\\"); } } else { strcat(gsdocbuf, "\\"); } strncpy(gsviewpathbuf, gsviewpath, sizeof(gsviewpathbuf)); if (!is_win32s) { /* The DDE interface isn't reliable with long names */ /* Convert everything to short names */ GetShortPathNameA(gspath, gspathbuf, sizeof(gspathbuf)); GetShortPathNameA(gsviewpath, gsviewpathbuf, sizeof(gsviewpathbuf)); } /* Open ProgMan DDE undo file if it doesn't exist */ strcpy(setup, gsviewpathbuf); strcat(setup, GSVIEW_ZIP); d = strrchr(setup, '.'); strcpy(d, "dde.log"); ddefile = fopen(setup, "r"); if (ddefile != (FILE *)NULL) { /* We found a previous ProgMan DDE undo file. */ /* Don't touch it since we want to keep the original record */ /* of the ProgMan state before GSview was installed */ fclose(ddefile); ddefile = (FILE *)NULL; } else { ddefile = fopen(setup, "w"); /* If we fail to open the file for writing, the destination is probably * read only. Don't worry, just don't write to the log file. */ } /* derive group filename from group name */ for (i=0, s=groupname, d=groupfile; i<8 && *s; s++) { if (isalpha((int)(*s)) || isdigit((int)(*s))) { *d++ = *s; i++; } } *d = '\0'; if (strlen(groupfile)==0) strcpy(groupfile, "gstools"); lpDdeProc = MakeProcInstance((FARPROC)DdeCallback, phInstance); if (DdeInitialize(&idInst, (PFNCALLBACK)lpDdeProc, CBF_FAIL_POKES, 0L)) { return 1; } hszServName = DdeCreateStringHandleA(idInst, "PROGMAN", CP_WINANSI); hszSysTopic = DdeCreateStringHandleA(idInst, "PROGMAN", CP_WINANSI); hConv = DdeConnect(idInst, hszServName, hszSysTopic, (PCONVCONTEXT)NULL); if (hConv == NULL) { DdeFreeStringHandle(idInst, hszServName); DdeFreeStringHandle(idInst, hszSysTopic); return 1; } if (ddefile) { /* Find out if group existed */ hszGroupsItem = DdeCreateStringHandleA(idInst, groupname, CP_WINANSI); hdata = DdeClientTransaction((LPBYTE)NULL, 0, hConv,\ hszGroupsItem, CF_TEXT, XTYP_REQUEST, 5000, &dwResult); DdeFreeStringHandle(idInst, hszGroupsItem); } #define DDEEXECUTE(str)\ DdeClientTransaction((LPBYTE)str, strlen(str)+1, hConv,\ NULL, CF_TEXT, XTYP_EXECUTE, 5000, &dwResult) sprintf(setup, "[CreateGroup(\042%s\042,%s.grp)][ShowGroup(\042%s\042,1)]", groupname, groupfile, groupname); /* display, active */ DDEEXECUTE(setup); if (ddefile) /* display, no active */ fprintf(ddefile, "[ShowGroup(\042%s\042,8)]\n",groupname); sprintf(setup, "[ReplaceItem(\042%s\042)]", GSVIEW_NAME); DDEEXECUTE(setup); #ifdef _WIN64 #define GSVIEW_ICON "gsview64.ico" #else #define GSVIEW_ICON "gsview32.ico" #endif if (!is_win4) sprintf(setup, "[AddItem(\042%s%s\042,\042%s\042, \042%s%s\042)]", gsviewpathbuf, GSVIEW_EXENAME, GSVIEW_NAME, gsviewpathbuf, GSVIEW_ICON); else sprintf(setup, "[AddItem(\042%s%s\042,\042%s\042)]", gsviewpathbuf, GSVIEW_EXENAME, GSVIEW_NAME); DDEEXECUTE(setup); if (ddefile) fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", GSVIEW_NAME); /* Win3.1 documentation says you must put quotes around names */ /* with embedded spaces. */ /* In Win95, it appears you must put quotes around the EXE name */ /* and options separately */ sprintf(setup, "[ReplaceItem(\042GSview README\042)]"); DDEEXECUTE(setup); #ifdef NOTUSED_IN_GSVIEW28 if (!is_win4) sprintf(setup, "[AddItem(\042notepad.exe %sREADME.TXT\042,\042GSview README\042)]", gsviewpathbuf); else sprintf(setup, "[AddItem(\042notepad.exe\042 \042%sREADME.TXT\042,\042GSview README\042,\042notepad.exe\042,1)]", gsviewpathbuf); #endif sprintf(setup, "[AddItem(\042%sReadme.htm\042,\042GSview README\042)]", gsviewpathbuf); DDEEXECUTE(setup); if (ddefile) fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", "GSview README"); sprintf(setup, "[ReplaceItem(\042Ghostscript\042)]"); DDEEXECUTE(setup); if (!is_win4) sprintf(setup, "[AddItem(\042%s%s -I%s\042,\042Ghostscript\042, \042%sgstext.ico\042)]", gspathbuf, GS_EXENAME, gsargs, gspathbuf); else sprintf(setup, "[AddItem(\042%s%s\042 \042-I%s\042,\042Ghostscript\042)]", gspathbuf, GS_EXENAME, gsargs); DDEEXECUTE(setup); if (ddefile) fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", "Ghostscript"); sprintf(setup, "[ReplaceItem(\042Ghostscript README\042)]"); DDEEXECUTE(setup); if (gsver >= 540) { sprintf(setup, "[AddItem(\042%sReadme.htm\042,\042Ghostscript README\042)]", gsdocbuf); } else { if (!is_win4) sprintf(setup, "[AddItem(\042notepad.exe %sREADME.\042,\042Ghostscript README\042)]", gsdocbuf); else sprintf(setup, "[AddItem(\042notepad.exe\042 \042%sREADME.\042,\042Ghostscript README\042, \042notepad.exe\042,1)]", gsdocbuf); } DDEEXECUTE(setup); if (ddefile) fprintf(ddefile, "[DeleteItem(\042%s\042)]\n", "Ghostscript README"); #undef DDEXECUTE /* Now remember the way things were */ if (ddefile) { if (hdata) { DWORD dlen; BYTE FAR *lpData = DdeAccessData(hdata, &dlen); LPSTR p, q; /* skip first line */ q = (LPSTR)lpData; while (*q && (*q != '\r') && (*q != '\n')) q++; while (*q && ((*q == '\r') || (*q == '\n'))) q++; p = q; /* for each group item */ while (*p) { /* skip to end of line */ while (*q && (*q != '\r') && (*q != '\n')) q++; strncpy(setup, p, (int)(q-p)+1); add_group_item(ddefile, setup); /* skip to start of next group name */ while (*q && ((*q == '\r') || (*q == '\n'))) q++; p = q; } if (ddefile) /* display, no active */ fprintf(ddefile, "[ShowGroup(\042%s\042,8)]\n",groupname); DdeUnaccessData(hdata); DdeFreeDataHandle(hdata); } else { /* group didn't exist before, so delete it */ fprintf(ddefile, "[DeleteGroup(\042%s\042)]\n", groupname); } fclose(ddefile); } DdeDisconnect(hConv); DdeFreeStringHandle(idInst, hszServName); DdeFreeStringHandle(idInst, hszSysTopic); DdeUninitialize(idInst); return 0; }
/***************************************************************** * DdeFreeDataHandle (DDEML.19) */ BOOL16 WINAPI DdeFreeDataHandle16(HDDEDATA hData) { return (BOOL16)DdeFreeDataHandle(hData); }
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 ); }
/****************************************************************** * WDML_ServerNameProc * * */ static LRESULT CALLBACK WDML_ServerNameProc(HWND hwndServer, UINT iMsg, WPARAM wParam, LPARAM lParam) { HWND hwndClient; HSZ hszApp, hszTop; HDDEDATA hDdeData = 0; WDML_INSTANCE* pInstance; UINT uiLo, uiHi; switch (iMsg) { case WM_DDE_INITIATE: /* wParam -- sending window handle LOWORD(lParam) -- application atom HIWORD(lParam) -- topic atom */ TRACE("WM_DDE_INITIATE message received!\n"); hwndClient = (HWND)wParam; pInstance = WDML_GetInstanceFromWnd(hwndServer); TRACE("idInst=%ld, threadID=0x%lx\n", pInstance->instanceID, GetCurrentThreadId()); if (!pInstance) return 0; /* don't free DDEParams, since this is a broadcast */ UnpackDDElParam(WM_DDE_INITIATE, lParam, &uiLo, &uiHi); hszApp = WDML_MakeHszFromAtom(pInstance, uiLo); hszTop = WDML_MakeHszFromAtom(pInstance, uiHi); if (!(pInstance->CBFflags & CBF_FAIL_CONNECTIONS)) { BOOL self = FALSE; CONVCONTEXT cc; CONVCONTEXT* pcc = NULL; WDML_CONV* pConv; char buf[256]; if (GetWindowThreadProcessId(hwndClient, NULL) == GetWindowThreadProcessId(hwndServer, NULL) && WDML_GetInstanceFromWnd(hwndClient) == WDML_GetInstanceFromWnd(hwndServer)) { self = TRUE; } /* FIXME: so far, we don't grab distant convcontext, so only check if remote is * handled under DDEML, and if so build a default context */ if ((GetClassNameA(hwndClient, buf, sizeof(buf)) && strcmp(buf, WDML_szClientConvClassA) == 0) || (GetClassNameW(hwndClient, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) && lstrcmpW((LPWSTR)buf, WDML_szClientConvClassW) == 0)) { pcc = &cc; memset(pcc, 0, sizeof(*pcc)); pcc->cb = sizeof(*pcc); pcc->iCodePage = IsWindowUnicode(hwndClient) ? CP_WINUNICODE : CP_WINANSI; } if ((pInstance->CBFflags & CBF_FAIL_SELFCONNECTIONS) && self) { TRACE("Don't do self connection as requested\n"); } else if (hszApp && hszTop) { WDML_SERVER* pServer = (WDML_SERVER*)GetWindowLongA(hwndServer, GWL_WDML_SERVER); /* check filters for name service */ if (!pServer->filterOn || DdeCmpStringHandles(pServer->hszService, hszApp) == 0) { /* pass on to the callback */ hDdeData = WDML_InvokeCallback(pInstance, XTYP_CONNECT, 0, 0, hszTop, hszApp, 0, (DWORD)pcc, self); if ((UINT)hDdeData) { pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer, hszApp, hszTop); if (pConv && pcc) pConv->wStatus |= ST_ISLOCAL; } } } else if (pInstance->servers) { /* pass on to the callback */ hDdeData = WDML_InvokeCallback(pInstance, XTYP_WILDCONNECT, 0, 0, hszTop, hszApp, 0, (DWORD)pcc, self); if (hDdeData == (HDDEDATA)CBR_BLOCK) { /* MS doc is not consistent here */ FIXME("CBR_BLOCK returned for WILDCONNECT\n"); } else if ((UINT)hDdeData != 0) { HSZPAIR* hszp; hszp = (HSZPAIR*)DdeAccessData(hDdeData, NULL); if (hszp) { int i; for (i = 0; hszp[i].hszSvc && hszp[i].hszTopic; i++) { pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer, hszp[i].hszSvc, hszp[i].hszTopic); if (pConv && pcc) pConv->wStatus |= ST_ISLOCAL; } DdeUnaccessData(hDdeData); } if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData); } } } return 0; case WM_DDE_REQUEST: FIXME("WM_DDE_REQUEST message received!\n"); return 0; case WM_DDE_ADVISE: FIXME("WM_DDE_ADVISE message received!\n"); return 0; case WM_DDE_UNADVISE: FIXME("WM_DDE_UNADVISE message received!\n"); return 0; case WM_DDE_EXECUTE: FIXME("WM_DDE_EXECUTE message received!\n"); return 0; case WM_DDE_POKE: FIXME("WM_DDE_POKE message received!\n"); return 0; case WM_DDE_TERMINATE: FIXME("WM_DDE_TERMINATE message received!\n"); return 0; } return DefWindowProcA(hwndServer, iMsg, wParam, lParam); }
static HDDEDATA CALLBACK DdeCallback(UINT type, UINT fmt, HCONV hconv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2) { switch(type) { case XTYP_CONNECT: { fid_t cid = PL_open_foreign_frame(); term_t argv = PL_new_term_refs(3); predicate_t pred = PL_pred(FUNCTOR_dde_connect3, MODULE_dde); int rval; PL_put_atom( argv+0, hszToAtom(hsz2)); /* topic */ PL_put_atom( argv+1, hszToAtom(hsz1)); /* service */ PL_put_integer(argv+2, dwData2 ? 1 : 0); /* same instance */ rval = PL_call_predicate(MODULE_dde, TRUE, pred, argv); PL_discard_foreign_frame(cid); return (void *)rval; } case XTYP_CONNECT_CONFIRM: { fid_t cid = PL_open_foreign_frame(); term_t argv = PL_new_term_refs(3); predicate_t pred = PL_pred(FUNCTOR_dde_connect_confirm3, MODULE_dde); int plhandle; if ( (plhandle = allocServerHandle(hconv)) >= 0 ) { fid_t cid = PL_open_foreign_frame(); term_t argv = PL_new_term_refs(3); predicate_t pred = PL_pred(FUNCTOR_dde_connect_confirm3, MODULE_dde); PL_put_atom( argv+0, hszToAtom(hsz2)); /* topic */ PL_put_atom( argv+1, hszToAtom(hsz1)); /* service */ PL_put_integer(argv+2, plhandle); PL_call_predicate(MODULE_dde, TRUE, pred, argv); PL_discard_foreign_frame(cid); } return NULL; } case XTYP_DISCONNECT: { fid_t cid = PL_open_foreign_frame(); term_t argv = PL_new_term_refs(1); predicate_t pred = PL_pred(FUNCTOR_dde_disconnect1, MODULE_dde); int plhandle = findServerHandle(hconv); if ( plhandle >= 0 && plhandle < MAX_CONVERSATIONS ) server_handle[plhandle] = (HCONV)NULL; PL_put_integer(argv+0, plhandle); PL_call_predicate(MODULE_dde, TRUE, pred, argv); PL_discard_foreign_frame(cid); return NULL; } case XTYP_EXECUTE: { int plhandle = findServerHandle(hconv); HDDEDATA rval = DDE_FNOTPROCESSED; fid_t cid = PL_open_foreign_frame(); term_t argv = PL_new_term_refs(3); predicate_t pred = PL_pred(FUNCTOR_dde_execute3, MODULE_dde); DEBUG(0, Sdprintf("Got XTYP_EXECUTE request\n")); PL_put_integer(argv+0, plhandle); PL_put_atom( argv+1, hszToAtom(hsz1)); unify_hdata( argv+2, hData); if ( PL_call_predicate(MODULE_dde, TRUE, pred, argv) ) rval = (void *) DDE_FACK; PL_discard_foreign_frame(cid); DdeFreeDataHandle(hData); return rval; } case XTYP_REQUEST: { HDDEDATA data = (HDDEDATA) NULL; if ( fmt == CF_TEXT ) { fid_t cid = PL_open_foreign_frame(); term_t argv = PL_new_term_refs(4); predicate_t pred = PL_pred(FUNCTOR_dde_request4, MODULE_dde); int plhandle = findServerHandle(hconv); PL_put_integer( argv+0, plhandle); PL_put_atom( argv+1, hszToAtom(hsz1)); /* topic */ PL_put_atom( argv+2, hszToAtom(hsz2)); /* item */ PL_put_variable(argv+3); if ( PL_call_predicate(MODULE_dde, TRUE, pred, argv) ) { char *s; if ( PL_get_chars(argv+3, &s, CVT_ALL) ) data = DdeCreateDataHandle(ddeInst, s, strlen(s)+1, 0, hsz2, CF_TEXT, 0); } PL_discard_foreign_frame(cid); } return data; } default: ; } return (HDDEDATA)NULL; }
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; }
DDEdataHandle::~DDEdataHandle() { if (hData) DdeFreeDataHandle(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; }