#include "wx/module.h"
#include "wx/dde.h"
+#include "wx/intl.h"
+
#include "wx/msw/private.h"
#include <windows.h>
#include <ddeml.h>
+#ifdef __WXWINE__
+#define PCONVCONTEXT CONVCONTEXT*
+#endif
+
#if defined(__TWIN32__) || defined(__GNUWIN32_OLD__)
#include "wx/msw/gnuwin32/extra.h"
#endif
+// some compilers headers don't define this one (mingw32)
+#ifndef DMLERR_NO_ERROR
+ #define DMLERR_NO_ERROR (0)
+
+ // this one is also missing from some mingw32 headers, but there is no way
+ // to test for it (I know of) - the test for DMLERR_NO_ERROR works for me,
+ // but is surely not the right thing to do
+ extern "C"
+ HDDEDATA STDCALL DdeClientTransaction(LPBYTE pData,
+ DWORD cbData,
+ HCONV hConv,
+ HSZ hszItem,
+ UINT wFmt,
+ UINT wType,
+ DWORD dwTimeout,
+ LPDWORD pdwResult);
+#endif // no DMLERR_NO_ERROR
+
// ----------------------------------------------------------------------------
// macros and constants
// ----------------------------------------------------------------------------
static wxList wxDDEClientObjects;
static wxList wxDDEServerObjects;
-char *DDEDefaultIPCBuffer = NULL;
-int DDEDefaultIPCBufferSize = 0;
static bool DDEInitialized = FALSE;
// ----------------------------------------------------------------------------
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;
}
// ----------------------------------------------------------------------------
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
wxNode *next = node->Next();
+ connection->SetConnected(false);
connection->OnDisconnect(); // May delete the node implicitly
node = next;
}
(PCONVCONTEXT)NULL);
if ( !hConv )
{
- DDELogError(wxString::Format(_("Failed to create connection to "
- "server '%s' on topic '%s'"),
+ DDELogError(wxString::Format(_("Failed to create connection to server '%s' on topic '%s'"),
server.c_str(), topic.c_str()));
}
else
// 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;
}
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
// Calls that CLIENT can make
bool wxDDEConnection::Disconnect()
{
+ if ( !GetConnected() )
+ return true;
+
DDEDeleteConnection(GetHConv());
bool ok = DdeDisconnect(GetHConv()) != 0;
DDELogError(_T("Failed to disconnect from DDE server gracefully"));
}
+ SetConnected( false ); // so we don't try and disconnect again
+
return ok;
}
XTYP_EXECUTE,
DDE_TIMEOUT,
&result) != 0;
+
if ( !ok )
{
DDELogError(_T("DDE execute request failed"));
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,
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)
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;
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;
}
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,
- connection->m_bufPtr,
+ data,
(int)len,
(wxIPCFormat) wFmt) )
{
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);
if (data)
{
if (user_size < 0)
- user_size = wxStrlen(data) + 1;
+ user_size = wxStrlen((wxChar*)data) + 1;
HDDEDATA handle = DdeCreateDataHandle(DDEIdInst,
(LPBYTE)data,
{
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,
- connection->m_bufPtr,
+ data,
(int)len,
(wxIPCFormat) wFmt);
{
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,
- connection->m_bufPtr,
+ data,
(int)len,
(wxIPCFormat) wFmt) )
{
{
wxASSERT_MSG( DDEIdInst, _T("DDE not initialized") );
- HSZ hsz = DdeCreateStringHandle(DDEIdInst, s, DDE_CP);
+ HSZ hsz = DdeCreateStringHandle(DDEIdInst, (wxChar*) s.c_str(), DDE_CP);
if ( !hsz )
{
DDELogError(_("Failed to create DDE string"));
err = _("a request for a synchronous data transaction has timed out.");
break;
case DMLERR_DLL_NOT_INITIALIZED:
- err = _("a DDEML function was called without first calling the DdeInitialize function,\n\ror an invalid instance identifier\n\rwas passed to a DDEML function.");
+ err = _("a DDEML function was called without first calling the DdeInitialize function,\nor an invalid instance identifier\nwas passed to a DDEML function.");
break;
case DMLERR_DLL_USAGE:
- err = _("an application initialized as APPCLASS_MONITOR has\n\rattempted to perform a DDE transaction,\n\ror an application initialized as APPCMD_CLIENTONLY has \n\rattempted to perform server transactions.");
+ err = _("an application initialized as APPCLASS_MONITOR has\nattempted to perform a DDE transaction,\nor an application initialized as APPCMD_CLIENTONLY has \nattempted to perform server transactions.");
break;
case DMLERR_EXECACKTIMEOUT:
err = _("a request for a synchronous execute transaction has timed out.");
err = _("reentrancy problem.");
break;
case DMLERR_SERVER_DIED:
- err = _("a server-side transaction was attempted on a conversation\n\rthat was terminated by the client, or the server\n\rterminated before completing a transaction.");
+ err = _("a server-side transaction was attempted on a conversation\nthat was terminated by the client, or the server\nterminated before completing a transaction.");
break;
case DMLERR_SYS_ERROR:
err = _("an internal error has occurred in the DDEML.");
err = _("a request to end an advise transaction has timed out.");
break;
case DMLERR_UNFOUND_QUEUE_ID:
- err = _("an invalid transaction identifier was passed to a DDEML function.\n\rOnce the application has returned from an XTYP_XACT_COMPLETE callback,\n\rthe transaction identifier for that callback is no longer valid.");
+ err = _("an invalid transaction identifier was passed to a DDEML function.\nOnce the application has returned from an XTYP_XACT_COMPLETE callback,\nthe transaction identifier for that callback is no longer valid.");
break;
default:
err.Printf(_("Unknown DDE error %08x"), error);