예제 #1
0
void CNetDDESvrApp::OnDDEDestroyConversation(CNetDDESvrSocket& oConnection, CNetDDEPacket& oReqPacket)
{
	ASSERT(oReqPacket.DataType() == CNetDDEPacket::DDE_DESTROY_CONVERSATION);

	HCONV  hConv;
	uint32 nConvID;

	// Decode message.
	CMemStream oStream(oReqPacket.Buffer());

	oStream.Open();
	oStream.Seek(sizeof(CNetDDEPacket::Header));

	oStream.Read(&hConv, sizeof(hConv));
	oStream >> nConvID;

	oStream.Close();

	if (App.m_bTraceConvs)
		App.Trace(TXT("DDE_DESTROY_CONVERSATION: 0x%p [#%u]"), hConv, nConvID);

	// Locate the conversation.
	CDDECltConv* pConv = m_pDDEClient->FindConversation(hConv);

	if (pConv != NULL)
	{
		CNetDDEConv* pNetConv = oConnection.FindNetConv(pConv, nConvID);

		ASSERT(pNetConv != NULL);

		try
		{
			// Not final reference?
			if (pNetConv->m_pSvrConv->RefCount() != 1)
			{
				// Destroy NetDDE conversations' links.
				for (size_t i = 0; i < pNetConv->m_aoLinks.Size(); ++i)
					pConv->DestroyLink(pNetConv->m_aoLinks[i]);
			}

			// Purge link cache, if last reference.
			if (pNetConv->m_pSvrConv->RefCount() == 1)
				m_oLinkCache.Purge(pConv);

			// Call DDE to terminate the conversation.
			m_pDDEClient->DestroyConversation(pConv);
		}
		catch (CDDEException& e)
		{
			App.Trace(TXT("DDE_ERROR: %s"), e.twhat());
		}

		// Detach from the connection.
		oConnection.m_aoNetConvs.Delete(oConnection.m_aoNetConvs.Find(pNetConv));
	}
}
예제 #2
0
void CNetDDESvrApp::OnDDEStopAdvise(CNetDDESvrSocket& oConnection, CNetDDEPacket& oReqPacket)
{
	ASSERT(oReqPacket.DataType() == CNetDDEPacket::DDE_STOP_ADVISE);

	HCONV	 hConv;
	uint32   nConvID;
	CString  strItem;
	uint32   nFormat;

	// Decode message.
	CMemStream oStream(oReqPacket.Buffer());

	oStream.Open();
	oStream.Seek(sizeof(CNetDDEPacket::Header));

	oStream.Read(&hConv, sizeof(hConv));
	oStream >> nConvID;
	oStream >> strItem;
	oStream >> nFormat;

	oStream.Close();

	if (App.m_bTraceAdvises)
		App.Trace(TXT("DDE_STOP_ADVISE: %s %s"), strItem, CClipboard::FormatName(nFormat));

	// Locate the conversation.
	CDDECltConv* pConv = m_pDDEClient->FindConversation(hConv);

	if (pConv != NULL)
	{
		// Locate the link. (May not exist, if async advised).
		CDDELink* pLink = pConv->FindLink(strItem, nFormat);

		if (pLink != NULL)
		{
			CNetDDEConv* pNetConv = oConnection.FindNetConv(pConv, nConvID);

			ASSERT(pNetConv != NULL);

			try
			{
				// Call DDE to destroy the link.
				pConv->DestroyLink(pLink);
			}
			catch (CDDEException& e)
			{
				App.Trace(TXT("DDE_ERROR: %s"), e.twhat());
			}

			// Detach from the connection.
			pNetConv->m_aoLinks.Remove(pNetConv->m_aoLinks.Find(pLink));
		}
	}
}