X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f565a6c2f4c6961c96dd330a98d0fa78f20ca8c0..4fa47e5643f13065af4269fd9a87b40e57d48c5f:/src/msw/dde.cpp diff --git a/src/msw/dde.cpp b/src/msw/dde.cpp index 327e727944..6cf22d6b56 100644 --- a/src/msw/dde.cpp +++ b/src/msw/dde.cpp @@ -46,6 +46,10 @@ #include #include +#ifdef __WXWINE__ +#define PCONVCONTEXT CONVCONTEXT* +#endif + #if defined(__TWIN32__) || defined(__GNUWIN32_OLD__) #include "wx/msw/gnuwin32/extra.h" #endif @@ -129,8 +133,6 @@ static wxList wxAtomTable(wxKEY_STRING); static wxList wxDDEClientObjects; static wxList wxDDEServerObjects; -char *DDEDefaultIPCBuffer = NULL; -int DDEDefaultIPCBufferSize = 0; static bool DDEInitialized = FALSE; // ---------------------------------------------------------------------------- @@ -189,13 +191,21 @@ extern void wxDDEInitialize() void wxDDECleanUp() { + wxDDEClientObjects.DeleteContents(TRUE); + wxDDEClientObjects.Clear(); + wxDDEClientObjects.DeleteContents(FALSE); + + wxDDEServerObjects.DeleteContents(TRUE); + wxDDEServerObjects.Clear(); + wxDDEServerObjects.DeleteContents(FALSE); + + wxAtomTable.Clear(); + if ( DDEIdInst != 0 ) { DdeUninitialize(DDEIdInst); DDEIdInst = 0; } - - delete [] DDEDefaultIPCBuffer; } // ---------------------------------------------------------------------------- @@ -310,6 +320,7 @@ wxDDEServer::~wxDDEServer() { wxDDEConnection *connection = (wxDDEConnection *)node->Data(); wxNode *next = node->Next(); + connection->SetConnected(false); connection->OnDisconnect(); // May delete the node implicitly node = next; } @@ -458,21 +469,9 @@ bool wxDDEClient::DeleteConnection(WXHCONV conv) // wxDDEConnection // ---------------------------------------------------------------------------- -wxDDEConnection::wxDDEConnection(char *buffer, int size) +wxDDEConnection::wxDDEConnection(wxChar *buffer, int size) + : wxConnectionBase(buffer, size) { - if (buffer == NULL) - { - if (DDEDefaultIPCBuffer == NULL) - DDEDefaultIPCBuffer = new char[DDEDefaultIPCBufferSize]; - m_bufPtr = DDEDefaultIPCBuffer; - m_bufSize = DDEDefaultIPCBufferSize; - } - else - { - m_bufPtr = buffer; - m_bufSize = size; - } - m_client = NULL; m_server = NULL; @@ -481,20 +480,17 @@ wxDDEConnection::wxDDEConnection(char *buffer, int size) } wxDDEConnection::wxDDEConnection() + : wxConnectionBase() { m_hConv = 0; m_sendingData = NULL; m_server = NULL; m_client = NULL; - if (DDEDefaultIPCBuffer == NULL) - DDEDefaultIPCBuffer = new char[DDEDefaultIPCBufferSize]; - - m_bufPtr = DDEDefaultIPCBuffer; - m_bufSize = DDEDefaultIPCBufferSize; } wxDDEConnection::~wxDDEConnection() { + Disconnect(); if (m_server) m_server->GetConnections().DeleteObject(this); else @@ -504,6 +500,9 @@ wxDDEConnection::~wxDDEConnection() // Calls that CLIENT can make bool wxDDEConnection::Disconnect() { + if ( !GetConnected() ) + return true; + DDEDeleteConnection(GetHConv()); bool ok = DdeDisconnect(GetHConv()) != 0; @@ -512,6 +511,8 @@ bool wxDDEConnection::Disconnect() DDELogError(_T("Failed to disconnect from DDE server gracefully")); } + SetConnected( false ); // so we don't try and disconnect again + return ok; } @@ -539,9 +540,10 @@ bool wxDDEConnection::Execute(const wxChar *data, int size, wxIPCFormat format) return ok; } -char *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat format) +wxChar *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat format) { DWORD result; + HSZ atom = DDEGetAtom(item); HDDEDATA returned_data = DdeClientTransaction(NULL, 0, @@ -557,14 +559,19 @@ char *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat form return NULL; } - DWORD len = DdeGetData(returned_data, (LPBYTE)m_bufPtr, m_bufSize, 0); + DWORD len = DdeGetData(returned_data, NULL, 0, 0); + + wxChar *data = GetBufferAtLeast( len ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in wxDDEConnection::Request") ); + DdeGetData(returned_data, (LPBYTE)data, len, 0); DdeFreeDataHandle(returned_data); if (size) *size = (int)len; - return m_bufPtr; + return data; } bool wxDDEConnection::Poke(const wxString& item, wxChar *data, int size, wxIPCFormat format) @@ -641,7 +648,7 @@ bool wxDDEConnection::Advise(const wxString& item, HSZ item_atom = DDEGetAtom(item); HSZ topic_atom = DDEGetAtom(m_topicName); - m_sendingData = data; + m_sendingData = data; // mrf: potential for scope problems here? m_dataSize = size; m_dataType = format; @@ -714,10 +721,14 @@ _DDECallback(WORD wType, case XTYP_DISCONNECT: { wxDDEConnection *connection = DDEFindConnection(hConv); - if (connection && connection->OnDisconnect()) + if (connection) { - DDEDeleteConnection(hConv); // Delete mapping: hConv => connection - return (DDERETURN)(DWORD)TRUE; + connection->SetConnected( false ); + if (connection->OnDisconnect()) + { + DDEDeleteConnection(hConv); // Delete mapping: hConv => connection + return (DDERETURN)(DWORD)TRUE; + } } break; } @@ -728,13 +739,18 @@ _DDECallback(WORD wType, if (connection) { - DWORD len = DdeGetData(hData, - (LPBYTE)connection->m_bufPtr, - connection->m_bufSize, - 0); + DWORD len = DdeGetData(hData, NULL, 0, 0); + + wxChar *data = connection->GetBufferAtLeast( len ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in _DDECallback (XTYP_EXECUTE)") ); + + DdeGetData(hData, (LPBYTE)data, len, 0); + DdeFreeDataHandle(hData); + if ( connection->OnExecute(connection->m_topicName, - (wxChar *) connection->m_bufPtr, + data, (int)len, (wxIPCFormat) wFmt) ) { @@ -754,7 +770,7 @@ _DDECallback(WORD wType, wxString item_name = DDEStringFromAtom(hsz2); int user_size = -1; - char *data = connection->OnRequest(connection->m_topicName, + wxChar *data = connection->OnRequest(connection->m_topicName, item_name, &user_size, (wxIPCFormat) wFmt); @@ -784,15 +800,19 @@ _DDECallback(WORD wType, { wxString item_name = DDEStringFromAtom(hsz2); - DWORD len = DdeGetData(hData, - (LPBYTE)connection->m_bufPtr, - connection->m_bufSize, - 0); + DWORD len = DdeGetData(hData, NULL, 0, 0); + + wxChar *data = connection->GetBufferAtLeast( len ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in _DDECallback (XTYP_EXECUTE)") ); + + DdeGetData(hData, (LPBYTE)data, len, 0); + DdeFreeDataHandle(hData); connection->OnPoke(connection->m_topicName, item_name, - (wxChar*)connection->m_bufPtr, + data, (int)len, (wxIPCFormat) wFmt); @@ -867,14 +887,18 @@ _DDECallback(WORD wType, { wxString item_name = DDEStringFromAtom(hsz2); - DWORD len = DdeGetData(hData, - (LPBYTE)connection->m_bufPtr, - connection->m_bufSize, - 0); + DWORD len = DdeGetData(hData, NULL, 0, 0); + + wxChar *data = connection->GetBufferAtLeast( len ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in _DDECallback (XTYP_ADVDATA)") ); + + DdeGetData(hData, (LPBYTE)data, len, 0); + DdeFreeDataHandle(hData); if ( connection->OnAdvise(connection->m_topicName, item_name, - (wxChar *) connection->m_bufPtr, + data, (int)len, (wxIPCFormat) wFmt) ) {