#include "wx/defs.h"
#endif
-#if USE_IPC
+#if wxUSE_IPC
#ifndef WX_PRECOMP
#include "wx/utils.h"
#include "wx/app.h"
#endif
-#include "wx/msw/private.h"
+#include "wx/module.h"
#include "wx/dde.h"
+#include "wx/msw/private.h"
+#include <windows.h>
+#include <ddeml.h>
+
+#ifndef __TWIN32__
#ifdef __GNUWIN32__
#include "wx/msw/gnuwin32/extra.h"
#endif
+#endif
-#include <windows.h>
-#include <ddeml.h>
#include <string.h>
#ifdef __WIN32__
delete [] DDEDefaultIPCBuffer ;
}
+// A module to allow DDE initialization/cleanup
+// without calling these functions from app.cpp or from
+// the user's application.
+
+class wxDDEModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(wxDDEModule)
+public:
+ wxDDEModule() {}
+ bool OnInit() { wxDDEInitialize(); return TRUE; };
+ void OnExit() { wxDDECleanUp(); };
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule)
+
// Global find connection
static wxDDEConnection *DDEFindConnection(HCONV hConv)
{
wxDDEServer::wxDDEServer(void)
{
- service_name = "";
+ m_serviceName = "";
wxDDEServerObjects.Append(this);
}
bool wxDDEServer::Create(const wxString& server_name)
{
- service_name = server_name;
- HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)server_name, CP_WINANSI);
+ m_serviceName = server_name;
+ HSZ serviceName = DdeCreateStringHandle(DDEIdInst, WXSTRINGCAST server_name, CP_WINANSI);
- if (DdeNameService(DDEIdInst, serviceName, NULL, DNS_REGISTER) == 0)
+ if (DdeNameService(DDEIdInst, serviceName, (HSZ) NULL, DNS_REGISTER) == 0)
{
DDEPrintError();
return FALSE;
wxDDEServer::~wxDDEServer(void)
{
- if (service_name != "")
+ if (m_serviceName != _T(""))
{
- HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)service_name, CP_WINANSI);
+ HSZ serviceName = DdeCreateStringHandle(DDEIdInst, WXSTRINGCAST m_serviceName, CP_WINANSI);
if (DdeNameService(DDEIdInst, serviceName, NULL, DNS_UNREGISTER) == 0)
{
DDEPrintError();
}
wxDDEServerObjects.DeleteObject(this);
- wxNode *node = connections.First();
+ wxNode *node = m_connections.First();
while (node)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
}
// If any left after this, delete them
- node = connections.First();
+ node = m_connections.First();
while (node)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
wxDDEConnection *wxDDEServer::FindConnection(WXHCONV conv)
{
- wxNode *node = connections.First();
+ wxNode *node = m_connections.First();
wxDDEConnection *found = NULL;
while (node && !found)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
- if (connection->hConv == conv)
+ if (connection->m_hConv == conv)
found = connection;
else node = node->Next();
}
// Only delete the entry in the map, not the actual connection
bool wxDDEServer::DeleteConnection(WXHCONV conv)
{
- wxNode *node = connections.First();
+ wxNode *node = m_connections.First();
bool found = FALSE;
while (node && !found)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
- if (connection->hConv == conv)
+ if (connection->m_hConv == conv)
{
found = TRUE;
delete node;
wxDDEClient::~wxDDEClient(void)
{
wxDDEClientObjects.DeleteObject(this);
- wxNode *node = connections.First();
+ wxNode *node = m_connections.First();
while (node)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
delete connection; // Deletes the node implicitly (see ~wxDDEConnection)
- node = connections.First();
+ node = m_connections.First();
}
}
wxConnectionBase *wxDDEClient::MakeConnection(const wxString& /* host */, const wxString& server_name, const wxString& topic)
{
- HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)server_name, CP_WINANSI);
- HSZ topic_atom = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)topic, CP_WINANSI);
+ HSZ serviceName = DdeCreateStringHandle(DDEIdInst, WXSTRINGCAST server_name, CP_WINANSI);
+ HSZ topic_atom = DdeCreateStringHandle(DDEIdInst, WXSTRINGCAST topic, CP_WINANSI);
HCONV hConv = DdeConnect(DDEIdInst, serviceName, topic_atom, (PCONVCONTEXT)NULL);
- if (hConv == NULL)
- return NULL;
+ if (hConv == (HCONV) NULL)
+ return (wxConnectionBase*) NULL;
else
{
wxDDEConnection *connection = (wxDDEConnection*) OnMakeConnection();
if (connection)
{
- connection->hConv = (WXHCONV) hConv;
- connection->topic_name = topic;
- connection->client = this;
- connections.Append(connection);
+ connection->m_hConv = (WXHCONV) hConv;
+ connection->m_topicName = topic;
+ connection->m_client = this;
+ m_connections.Append(connection);
return connection;
}
- else return NULL;
+ else return (wxConnectionBase*) NULL;
}
}
wxDDEConnection *wxDDEClient::FindConnection(WXHCONV conv)
{
- wxNode *node = connections.First();
+ wxNode *node = m_connections.First();
wxDDEConnection *found = NULL;
while (node && !found)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
- if (connection->hConv == conv)
+ if (connection->m_hConv == conv)
found = connection;
else node = node->Next();
}
// Only delete the entry in the map, not the actual connection
bool wxDDEClient::DeleteConnection(WXHCONV conv)
{
- wxNode *node = connections.First();
+ wxNode *node = m_connections.First();
bool found = FALSE;
while (node && !found)
{
wxDDEConnection *connection = (wxDDEConnection *)node->Data();
- if (connection->hConv == conv)
+ if (connection->m_hConv == conv)
{
found = TRUE;
delete node;
{
if (DDEDefaultIPCBuffer == NULL)
DDEDefaultIPCBuffer = new char[DDEDefaultIPCBufferSize];
- buf_ptr = DDEDefaultIPCBuffer;
- buf_size = DDEDefaultIPCBufferSize;
+ m_bufPtr = DDEDefaultIPCBuffer;
+ m_bufSize = DDEDefaultIPCBufferSize;
}
else
{
- buf_ptr = buffer;
- buf_size = size;
+ m_bufPtr = buffer;
+ m_bufSize = size;
}
- topic_name = "";
+ m_topicName = "";
- client = NULL;
- server = NULL;
+ m_client = NULL;
+ m_server = NULL;
- hConv = 0;
- sending_data = NULL;
+ m_hConv = 0;
+ m_sendingData = NULL;
}
wxDDEConnection::wxDDEConnection(void)
{
- hConv = 0;
- sending_data = NULL;
- server = NULL;
- client = NULL;
+ m_hConv = 0;
+ m_sendingData = NULL;
+ m_server = NULL;
+ m_client = NULL;
if (DDEDefaultIPCBuffer == NULL)
DDEDefaultIPCBuffer = new char[DDEDefaultIPCBufferSize];
- buf_ptr = DDEDefaultIPCBuffer;
- buf_size = DDEDefaultIPCBufferSize;
- topic_name = "";
+ m_bufPtr = DDEDefaultIPCBuffer;
+ m_bufSize = DDEDefaultIPCBufferSize;
+ m_topicName = "";
}
wxDDEConnection::~wxDDEConnection(void)
{
- if (server)
- server->GetConnections().DeleteObject(this);
+ if (m_server)
+ m_server->GetConnections().DeleteObject(this);
else
- client->GetConnections().DeleteObject(this);
+ m_client->GetConnections().DeleteObject(this);
}
// Calls that CLIENT can make
bool wxDDEConnection::Disconnect(void)
{
- DDEDeleteConnection((HCONV) hConv);
- return (DdeDisconnect((HCONV) hConv) != 0);
+ DDEDeleteConnection((HCONV) m_hConv);
+ return (DdeDisconnect((HCONV) m_hConv) != 0);
}
-bool wxDDEConnection::Execute(char *data, int size, int format)
+bool wxDDEConnection::Execute(wxChar *data, int size, wxIPCFormat format)
{
DWORD result;
if (size < 0)
- size = strlen(data);
+ size = wxStrlen(data);
size ++;
- return (DdeClientTransaction((LPBYTE)data, size, (HCONV) hConv,
+ return (DdeClientTransaction((LPBYTE)data, size, (HCONV) m_hConv,
NULL, format, XTYP_EXECUTE, 5000, &result) ? TRUE : FALSE);
}
-char *wxDDEConnection::Request(const wxString& item, int *size, int format)
+char *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat format)
{
DWORD result;
HSZ atom = DDEGetAtom(item);
- HDDEDATA returned_data = DdeClientTransaction(NULL, 0, (HCONV) hConv,
+ HDDEDATA returned_data = DdeClientTransaction(NULL, 0, (HCONV) m_hConv,
atom, format, XTYP_REQUEST, 5000, &result);
- DWORD len = DdeGetData(returned_data, (LPBYTE)(buf_ptr), buf_size, 0);
+ DWORD len = DdeGetData(returned_data, (LPBYTE)(m_bufPtr), m_bufSize, 0);
DdeFreeDataHandle(returned_data);
if (size) *size = (int)len;
if (len > 0)
{
- return buf_ptr;
+ return m_bufPtr;
}
else return NULL;
}
-bool wxDDEConnection::Poke(const wxString& item, char *data, int size, int format)
+bool wxDDEConnection::Poke(const wxString& item, wxChar *data, int size, wxIPCFormat format)
{
DWORD result;
if (size < 0)
- size = strlen(data);
+ size = wxStrlen(data);
size ++;
HSZ item_atom = DDEGetAtom(item);
- return (DdeClientTransaction((LPBYTE)data, size, (HCONV) hConv,
+ return (DdeClientTransaction((LPBYTE)data, size, (HCONV) m_hConv,
item_atom, format, XTYP_POKE, 5000, &result) ? TRUE : FALSE);
}
DWORD result;
HSZ atom = DDEGetAtom(item);
- return (DdeClientTransaction(NULL, 0, (HCONV) hConv,
+ return (DdeClientTransaction(NULL, 0, (HCONV) m_hConv,
atom, CF_TEXT, XTYP_ADVSTART, 5000, &result) ? TRUE : FALSE);
}
DWORD result;
HSZ atom = DDEGetAtom(item);
- return (DdeClientTransaction(NULL, 0, (HCONV) hConv,
+ return (DdeClientTransaction(NULL, 0, (HCONV) m_hConv,
atom, CF_TEXT, XTYP_ADVSTOP, 5000, &result) ? TRUE : FALSE);
}
// Calls that SERVER can make
-bool wxDDEConnection::Advise(const wxString& item, char *data, int size, int format)
+bool wxDDEConnection::Advise(const wxString& item, wxChar *data, int size, wxIPCFormat format)
{
if (size < 0)
- size = strlen(data);
+ size = wxStrlen(data);
size ++;
HSZ item_atom = DDEGetAtom(item);
- HSZ topic_atom = DDEGetAtom(topic_name);
- sending_data = data;
- data_size = size;
- data_type = format;
+ HSZ topic_atom = DDEGetAtom(m_topicName);
+ m_sendingData = data;
+ m_dataSize = size;
+ m_dataType = format;
return (DdePostAdvise(DDEIdInst, topic_atom, item_atom) != 0);
}
{
case XTYP_CONNECT:
{
- char topic_buf[100];
- char server_buf[100];
- DdeQueryString(DDEIdInst, hsz1, (LPSTR)topic_buf, sizeof(topic_buf),
+ wxChar topic_buf[100];
+ wxChar server_buf[100];
+ DdeQueryString(DDEIdInst, hsz1, (LPTSTR)topic_buf, WXSIZEOF(topic_buf),
CP_WINANSI);
- DdeQueryString(DDEIdInst, hsz2, (LPSTR)server_buf, sizeof(topic_buf),
+ DdeQueryString(DDEIdInst, hsz2, (LPTSTR)server_buf, WXSIZEOF(topic_buf),
CP_WINANSI);
wxDDEServer *server = DDEFindServer(server_buf);
if (server)
(wxDDEConnection*) server->OnAcceptConnection(wxString(topic_buf));
if (connection)
{
- connection->server = server;
+ connection->m_server = server;
server->GetConnections().Append(connection);
- connection->hConv = 0;
- connection->topic_name = topic_buf;
+ connection->m_hConv = 0;
+ connection->m_topicName = topic_buf;
DDECurrentlyConnecting = connection;
return (DDERETURN)TRUE;
}
{
if (DDECurrentlyConnecting)
{
- DDECurrentlyConnecting->hConv = (WXHCONV) hConv;
+ DDECurrentlyConnecting->m_hConv = (WXHCONV) hConv;
DDECurrentlyConnecting = NULL;
return (DDERETURN)TRUE;
}
if (connection)
{
- DWORD len = DdeGetData(hData, (LPBYTE)(connection->buf_ptr), connection->buf_size, 0);
+ DWORD len = DdeGetData(hData, (LPBYTE)(connection->m_bufPtr), connection->m_bufSize, 0);
DdeFreeDataHandle(hData);
- if (connection->OnExecute(connection->topic_name, connection->buf_ptr, (int)len, wFmt))
+ if (connection->OnExecute(connection->m_topicName, connection->m_bufPtr, (int)len, (wxIPCFormat) wFmt))
return (DDERETURN)DDE_FACK;
else
return (DDERETURN)DDE_FNOTPROCESSED;
if (connection)
{
- char item_name[200];
- DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
+ wxChar item_name[200];
+ DdeQueryString(DDEIdInst, hsz2, (LPTSTR)item_name, WXSIZEOF(item_name),
CP_WINANSI);
int user_size = -1;
- char *data = connection->OnRequest(connection->topic_name, wxString(item_name), &user_size, wFmt);
+ char *data = connection->OnRequest(connection->m_topicName, wxString(item_name), &user_size, (wxIPCFormat) wFmt);
if (data)
{
if (user_size < 0) user_size = strlen(data);
if (connection)
{
- char item_name[200];
- DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
+ wxChar item_name[200];
+ DdeQueryString(DDEIdInst, hsz2, (LPTSTR)item_name, WXSIZEOF(item_name),
CP_WINANSI);
- DWORD len = DdeGetData(hData, (LPBYTE)(connection->buf_ptr), connection->buf_size, 0);
+ DWORD len = DdeGetData(hData, (LPBYTE)(connection->m_bufPtr), connection->m_bufSize, 0);
DdeFreeDataHandle(hData);
- connection->OnPoke(connection->topic_name, wxString(item_name), connection->buf_ptr, (int)len, wFmt);
+ connection->OnPoke(connection->m_topicName, wxString(item_name), connection->m_bufPtr, (int)len, (wxIPCFormat) wFmt);
return (DDERETURN)DDE_FACK;
} else return (DDERETURN)DDE_FNOTPROCESSED;
break;
if (connection)
{
- char item_name[200];
- DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
+ wxChar item_name[200];
+ DdeQueryString(DDEIdInst, hsz2, (LPTSTR)item_name, WXSIZEOF(item_name),
CP_WINANSI);
- return (DDERETURN)connection->OnStartAdvise(connection->topic_name, wxString(item_name));
+ return (DDERETURN)connection->OnStartAdvise(connection->m_topicName, wxString(item_name));
} else return (DDERETURN)0;
break;
}
if (connection)
{
- char item_name[200];
- DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
+ wxChar item_name[200];
+ DdeQueryString(DDEIdInst, hsz2, (LPTSTR)item_name, WXSIZEOF(item_name),
CP_WINANSI);
- return (DDERETURN)connection->OnStopAdvise(connection->topic_name, wxString(item_name));
+ return (DDERETURN)connection->OnStopAdvise(connection->m_topicName, wxString(item_name));
} else return (DDERETURN)0;
break;
}
{
wxDDEConnection *connection = DDEFindConnection(hConv);
- if (connection && connection->sending_data)
+ if (connection && connection->m_sendingData)
{
HDDEDATA data = DdeCreateDataHandle(DDEIdInst,
- (LPBYTE)connection->sending_data,
- connection->data_size, 0, hsz2, connection->data_type, 0);
- connection->sending_data = NULL;
+ (LPBYTE)connection->m_sendingData,
+ connection->m_dataSize, 0, hsz2, connection->m_dataType, 0);
+ connection->m_sendingData = NULL;
return (DDERETURN)data;
} else return (DDERETURN)NULL;
break;
if (connection)
{
- char item_name[200];
- DdeQueryString(DDEIdInst, hsz2, (LPSTR)item_name, sizeof(item_name),
+ wxChar item_name[200];
+ DdeQueryString(DDEIdInst, hsz2, (LPTSTR)item_name, WXSIZEOF(item_name),
CP_WINANSI);
- DWORD len = DdeGetData(hData, (LPBYTE)(connection->buf_ptr), connection->buf_size, 0);
+ DWORD len = DdeGetData(hData, (LPBYTE)(connection->m_bufPtr), connection->m_bufSize, 0);
DdeFreeDataHandle(hData);
- if (connection->OnAdvise(connection->topic_name, wxString(item_name), connection->buf_ptr, (int)len, wFmt))
+ if (connection->OnAdvise(connection->m_topicName, wxString(item_name), connection->m_bufPtr, (int)len, (wxIPCFormat) wFmt))
return (DDERETURN)DDE_FACK;
else
return (DDERETURN)DDE_FNOTPROCESSED;
// Atom table stuff
static HSZ DDEAddAtom(const wxString& string)
{
- HSZ atom = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)string, CP_WINANSI);
+ HSZ atom = DdeCreateStringHandle(DDEIdInst, WXSTRINGCAST string, CP_WINANSI);
wxAtomTable.Append(string, (wxObject *)atom);
return atom;
}
void DDEPrintError(void)
{
- char *err = NULL;
+ wxChar *err = NULL;
switch (DdeGetLastError(DDEIdInst))
{
case DMLERR_ADVACKTIMEOUT:
- err = "A request for a synchronous advise transaction has timed out.";
+ err = _T("A request for a synchronous advise transaction has timed out.");
break;
case DMLERR_BUSY:
- err = "The response to the transaction caused the DDE_FBUSY bit to be set.";
+ err = _T("The response to the transaction caused the DDE_FBUSY bit to be set.");
break;
case DMLERR_DATAACKTIMEOUT:
- err = "A request for a synchronous data transaction has timed out.";
+ err = _T("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 = _T("A DDEML function was called without first calling the DdeInitialize function,\n\ror an invalid instance identifier\n\rwas 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 = _T("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.");
break;
case DMLERR_EXECACKTIMEOUT:
- err = "A request for a synchronous execute transaction has timed out.";
+ err = _T("A request for a synchronous execute transaction has timed out.");
break;
case DMLERR_INVALIDPARAMETER:
- err = "A parameter failed to be validated by the DDEML.";
+ err = _T("A parameter failed to be validated by the DDEML.");
break;
case DMLERR_LOW_MEMORY:
- err = "A DDEML application has created a prolonged race condition.";
+ err = _T("A DDEML application has created a prolonged race condition.");
break;
case DMLERR_MEMORY_ERROR:
- err = "A memory allocation failed.";
+ err = _T("A memory allocation failed.");
break;
case DMLERR_NO_CONV_ESTABLISHED:
- err = "A client's attempt to establish a conversation has failed.";
+ err = _T("A client's attempt to establish a conversation has failed.");
break;
case DMLERR_NOTPROCESSED:
- err = "A transaction failed.";
+ err = _T("A transaction failed.");
break;
case DMLERR_POKEACKTIMEOUT:
- err = "A request for a synchronous poke transaction has timed out.";
+ err = _T("A request for a synchronous poke transaction has timed out.");
break;
case DMLERR_POSTMSG_FAILED:
- err = "An internal call to the PostMessage function has failed. ";
+ err = _T("An internal call to the PostMessage function has failed. ");
break;
case DMLERR_REENTRANCY:
- err = "Reentrancy problem.";
+ err = _T("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 = _T("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.");
break;
case DMLERR_SYS_ERROR:
- err = "An internal error has occurred in the DDEML.";
+ err = _T("An internal error has occurred in the DDEML.");
break;
case DMLERR_UNADVACKTIMEOUT:
- err = "A request to end an advise transaction has timed out.";
+ err = _T("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 = _T("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.");
break;
default:
- err = "Unrecognised error type.";
+ err = _T("Unrecognised error type.");
break;
}
- MessageBox(NULL, (LPCSTR)err, "DDE Error", MB_OK | MB_ICONINFORMATION);
+ MessageBox((HWND) NULL, (LPCTSTR)err, _T("DDE Error"), MB_OK | MB_ICONINFORMATION);
}
#endif
- // USE_IPC
+ // wxUSE_IPC