#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
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;
}
// 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;
}
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,
- (wxChar *) 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);
{
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);
{
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) )
{