X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/df5168c427b51f1ab2b3200a5c8f7626b3d24aae..ab5ebf521fca1ddff1de556db7c53b25b501cdeb:/src/msw/dde.cpp diff --git a/src/msw/dde.cpp b/src/msw/dde.cpp index cb98067949..6554c530de 100644 --- a/src/msw/dde.cpp +++ b/src/msw/dde.cpp @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "dde.h" #endif @@ -43,7 +43,6 @@ #include "wx/msw/private.h" #include -#include #include #ifdef __GNUWIN32_OLD__ @@ -113,6 +112,7 @@ static HSZ DDEGetAtom(const wxString& string); // string handles static HSZ DDEAtomFromString(const wxString& s); static wxString DDEStringFromAtom(HSZ hsz); +static void DDEFreeString(HSZ hsz); // error handling static wxString DDEGetErrorMsg(UINT error); @@ -195,8 +195,10 @@ extern void wxDDEInitialize() void wxDDECleanUp() { - WX_CLEAR_LIST(wxDDEClientList, wxDDEClientObjects); - WX_CLEAR_LIST(wxDDEServerList, wxDDEServerObjects); + // deleting them later won't work as DDE won't be initialized any more + wxASSERT_MSG( wxDDEServerObjects.empty() && + wxDDEClientObjects.empty(), + _T("all DDE objects should be deleted by now") ); wxAtomTable.clear(); @@ -300,26 +302,45 @@ bool wxDDEServer::Create(const wxString& server) { m_serviceName = server; - if ( !DdeNameService(DDEIdInst, DDEAtomFromString(server), (HSZ)NULL, DNS_REGISTER) ) - { - DDELogError(wxString::Format(_("Failed to register DDE server '%s'"), - server.c_str())); + HSZ hsz = DDEAtomFromString(server); + if ( !hsz ) + { return false; } - return true; + + bool success = (DdeNameService(DDEIdInst, hsz, (HSZ) NULL, DNS_REGISTER) + != NULL); + + if (!success) + { + DDELogError(wxString::Format(_("Failed to register DDE server '%s'"), + server.c_str())); + } + + DDEFreeString(hsz); + + return success; } wxDDEServer::~wxDDEServer() { if ( !!m_serviceName ) { - if ( !DdeNameService(DDEIdInst, DDEAtomFromString(m_serviceName), - (HSZ)NULL, DNS_UNREGISTER) ) + HSZ hsz = DDEAtomFromString(m_serviceName); + + if (hsz) { - DDELogError(wxString::Format(_("Failed to unregister DDE server '%s'"), - m_serviceName.c_str())); + if ( !DdeNameService(DDEIdInst, hsz, + (HSZ) NULL, DNS_UNREGISTER) ) + { + DDELogError(wxString::Format( + _("Failed to unregister DDE server '%s'"), + m_serviceName.c_str())); + } + + DDEFreeString(hsz); } } @@ -417,12 +438,35 @@ wxConnectionBase *wxDDEClient::MakeConnection(const wxString& WXUNUSED(host), const wxString& server, const wxString& topic) { - HCONV hConv = DdeConnect(DDEIdInst, DDEAtomFromString(server), DDEAtomFromString(topic), - (PCONVCONTEXT)NULL); + HSZ hszServer = DDEAtomFromString(server); + + if ( !hszServer ) + { + return (wxConnectionBase*) NULL; + } + + + HSZ hszTopic = DDEAtomFromString(topic); + + if ( !hszTopic ) + { + DDEFreeString(hszServer); + return (wxConnectionBase*) NULL; + } + + + HCONV hConv = ::DdeConnect(DDEIdInst, hszServer, hszTopic, + (PCONVCONTEXT) NULL); + + DDEFreeString(hszServer); + DDEFreeString(hszTopic); + + if ( !hConv ) { - DDELogError(wxString::Format(_("Failed to create connection to server '%s' on topic '%s'"), - server.c_str(), topic.c_str())); + DDELogError( wxString::Format( + _("Failed to create connection to server '%s' on topic '%s'"), + server.c_str(), topic.c_str()) ); } else { @@ -575,9 +619,9 @@ wxChar *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat fo wxChar *data = GetBufferAtLeast( len ); wxASSERT_MSG(data != NULL, _T("Buffer too small in wxDDEConnection::Request") ); - DdeGetData(returned_data, (LPBYTE)data, len, 0); + (void) DdeGetData(returned_data, (LPBYTE)data, len, 0); - DdeFreeDataHandle(returned_data); + (void) DdeFreeDataHandle(returned_data); if (size) *size = (int)len; @@ -946,7 +990,10 @@ static HSZ DDEGetAtom(const wxString& str) return DDEAddAtom(str); } -// atom <-> strings +/* atom <-> strings +The returned handle has to be freed by the caller (using +(static) DDEFreeString). +*/ static HSZ DDEAtomFromString(const wxString& s) { wxASSERT_MSG( DDEIdInst, _T("DDE not initialized") ); @@ -966,12 +1013,20 @@ static wxString DDEStringFromAtom(HSZ hsz) static const size_t len = 256; wxString s; - (void)DdeQueryString(DDEIdInst, hsz, s.GetWriteBuf(len), len, DDE_CP); - s.UngetWriteBuf(); + (void)DdeQueryString(DDEIdInst, hsz, wxStringBuffer(s, len), len, DDE_CP); return s; } +static void DDEFreeString(HSZ hsz) +{ + // DS: Failure to free a string handle might indicate there's + // some other severe error. + bool ok = (::DdeFreeStringHandle(DDEIdInst, hsz) != 0); + wxASSERT_MSG( ok, wxT("Failed to free DDE string handle") ); + wxUnusedVar(ok); +} + // ---------------------------------------------------------------------------- // error handling // ----------------------------------------------------------------------------