// 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);
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();
{
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);
}
}
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
{
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;
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") );
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
// ----------------------------------------------------------------------------