X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b3324be240257cb1a97c439616a1d58cb3b437cc..37b8e6798782278fdfe4f3c1291aaff55cdbb8c9:/src/msw/dde.cpp diff --git a/src/msw/dde.cpp b/src/msw/dde.cpp index d829167ae1..275f56144f 100644 --- a/src/msw/dde.cpp +++ b/src/msw/dde.cpp @@ -24,22 +24,28 @@ #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 +#include + +#ifndef __TWIN32__ +#if !wxUSE_NORLANDER_HEADERS #ifdef __GNUWIN32__ #include "wx/msw/gnuwin32/extra.h" #endif +#endif +#endif -#include -#include #include #ifdef __WIN32__ @@ -48,11 +54,9 @@ #define _EXPORT _export #endif -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxDDEServer, wxServerBase) IMPLEMENT_DYNAMIC_CLASS(wxDDEClient, wxClientBase) IMPLEMENT_CLASS(wxDDEConnection, wxConnectionBase) -#endif static wxDDEConnection *DDEFindConnection(HCONV hConv); static void DDEDeleteConnection(HCONV hConv); @@ -118,6 +122,21 @@ void wxDDECleanUp() 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) { @@ -156,7 +175,7 @@ static void DDEDeleteConnection(HCONV hConv) if (found) return; - node = wxDDEServerObjects.First(); + node = wxDDEClientObjects.First(); while (node && !found) { wxDDEClient *object = (wxDDEClient *)node->Data(); @@ -195,9 +214,9 @@ wxDDEServer::wxDDEServer(void) bool wxDDEServer::Create(const wxString& server_name) { m_serviceName = server_name; - HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)server_name, CP_WINANSI); + 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; @@ -207,9 +226,9 @@ bool wxDDEServer::Create(const wxString& server_name) wxDDEServer::~wxDDEServer(void) { - if (m_serviceName != "") + if (m_serviceName != wxT("")) { - HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (char*) (const char *)m_serviceName, CP_WINANSI); + HSZ serviceName = DdeCreateStringHandle(DDEIdInst, WXSTRINGCAST m_serviceName, CP_WINANSI); if (DdeNameService(DDEIdInst, serviceName, NULL, DNS_UNREGISTER) == 0) { DDEPrintError(); @@ -305,12 +324,12 @@ bool wxDDEClient::ValidHost(const wxString& /* host */) 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(); @@ -322,7 +341,7 @@ wxConnectionBase *wxDDEClient::MakeConnection(const wxString& /* host */, const m_connections.Append(connection); return connection; } - else return NULL; + else return (wxConnectionBase*) NULL; } } @@ -420,11 +439,11 @@ bool wxDDEConnection::Disconnect(void) return (DdeDisconnect((HCONV) m_hConv) != 0); } -bool wxDDEConnection::Execute(char *data, int size, wxDataFormat format) +bool wxDDEConnection::Execute(const wxChar *data, int size, wxIPCFormat format) { DWORD result; if (size < 0) - size = strlen(data); + size = wxStrlen(data); size ++; @@ -432,7 +451,7 @@ bool wxDDEConnection::Execute(char *data, int size, wxDataFormat format) NULL, format, XTYP_EXECUTE, 5000, &result) ? TRUE : FALSE); } -char *wxDDEConnection::Request(const wxString& item, int *size, wxDataFormat format) +char *wxDDEConnection::Request(const wxString& item, int *size, wxIPCFormat format) { DWORD result; HSZ atom = DDEGetAtom(item); @@ -452,11 +471,11 @@ char *wxDDEConnection::Request(const wxString& item, int *size, wxDataFormat for else return NULL; } -bool wxDDEConnection::Poke(const wxString& item, char *data, int size, wxDataFormat 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 ++; @@ -484,10 +503,10 @@ bool wxDDEConnection::StopAdvise(const wxString& item) } // Calls that SERVER can make -bool wxDDEConnection::Advise(const wxString& item, char *data, int size, wxDataFormat format) +bool wxDDEConnection::Advise(const wxString& item, wxChar *data, int size, wxIPCFormat format) { if (size < 0) - size = strlen(data); + size = wxStrlen(data); size ++; @@ -522,11 +541,11 @@ DWORD /* lData2 */) { 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) @@ -540,7 +559,7 @@ DWORD /* lData2 */) connection->m_hConv = 0; connection->m_topicName = topic_buf; DDECurrentlyConnecting = connection; - return (DDERETURN)TRUE; + return (DDERETURN)(DWORD)TRUE; } } else return (DDERETURN)0; @@ -553,7 +572,7 @@ DWORD /* lData2 */) { DDECurrentlyConnecting->m_hConv = (WXHCONV) hConv; DDECurrentlyConnecting = NULL; - return (DDERETURN)TRUE; + return (DDERETURN)(DWORD)TRUE; } else return 0; break; @@ -565,7 +584,7 @@ DWORD /* lData2 */) if (connection && connection->OnDisconnect()) { DDEDeleteConnection(hConv); // Delete mapping: hConv => connection - return (DDERETURN)TRUE; + return (DDERETURN)(DWORD)TRUE; } else return (DDERETURN)0; break; @@ -579,8 +598,8 @@ DWORD /* lData2 */) { DWORD len = DdeGetData(hData, (LPBYTE)(connection->m_bufPtr), connection->m_bufSize, 0); DdeFreeDataHandle(hData); - if (connection->OnExecute(connection->m_topicName, connection->m_bufPtr, (int)len, (wxDataFormat) wFmt)) - return (DDERETURN)DDE_FACK; + if (connection->OnExecute(connection->m_topicName, connection->m_bufPtr, (int)len, (wxIPCFormat) wFmt)) + return (DDERETURN)(DWORD)DDE_FACK; else return (DDERETURN)DDE_FNOTPROCESSED; } else return (DDERETURN)DDE_FNOTPROCESSED; @@ -593,12 +612,12 @@ DWORD /* lData2 */) 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->m_topicName, wxString(item_name), &user_size, (wxDataFormat) 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); @@ -617,13 +636,13 @@ DWORD /* lData2 */) 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->m_bufPtr), connection->m_bufSize, 0); DdeFreeDataHandle(hData); - connection->OnPoke(connection->m_topicName, wxString(item_name), connection->m_bufPtr, (int)len, (wxDataFormat) wFmt); - return (DDERETURN)DDE_FACK; + connection->OnPoke(connection->m_topicName, wxString(item_name), connection->m_bufPtr, (int)len, (wxIPCFormat) wFmt); + return (DDERETURN)(DWORD)DDE_FACK; } else return (DDERETURN)DDE_FNOTPROCESSED; break; } @@ -634,11 +653,11 @@ DWORD /* lData2 */) 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->m_topicName, wxString(item_name)); + return (DDERETURN)(DWORD)connection->OnStartAdvise(connection->m_topicName, wxString(item_name)); } else return (DDERETURN)0; break; } @@ -649,10 +668,10 @@ DWORD /* lData2 */) 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->m_topicName, wxString(item_name)); + return (DDERETURN)(DWORD)connection->OnStopAdvise(connection->m_topicName, wxString(item_name)); } else return (DDERETURN)0; break; } @@ -678,14 +697,14 @@ DWORD /* lData2 */) 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->m_bufPtr), connection->m_bufSize, 0); DdeFreeDataHandle(hData); - if (connection->OnAdvise(connection->m_topicName, wxString(item_name), connection->m_bufPtr, (int)len, (wxDataFormat) wFmt)) - return (DDERETURN)DDE_FACK; + if (connection->OnAdvise(connection->m_topicName, wxString(item_name), connection->m_bufPtr, (int)len, (wxIPCFormat) wFmt)) + return (DDERETURN)(DWORD)DDE_FACK; else return (DDERETURN)DDE_FNOTPROCESSED; } else return (DDERETURN)DDE_FNOTPROCESSED; @@ -698,7 +717,7 @@ DWORD /* lData2 */) // 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; } @@ -717,69 +736,69 @@ static HSZ DDEGetAtom(const wxString& string) 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 = wxT("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 = wxT("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 = wxT("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 = wxT("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 = wxT("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 = wxT("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 = wxT("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 = wxT("A DDEML application has created a prolonged race condition."); break; case DMLERR_MEMORY_ERROR: - err = "A memory allocation failed."; + err = wxT("A memory allocation failed."); break; case DMLERR_NO_CONV_ESTABLISHED: - err = "A client's attempt to establish a conversation has failed."; + err = wxT("A client's attempt to establish a conversation has failed."); break; case DMLERR_NOTPROCESSED: - err = "A transaction failed."; + err = wxT("A transaction failed."); break; case DMLERR_POKEACKTIMEOUT: - err = "A request for a synchronous poke transaction has timed out."; + err = wxT("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 = wxT("An internal call to the PostMessage function has failed. "); break; case DMLERR_REENTRANCY: - err = "Reentrancy problem."; + err = wxT("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 = wxT("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 = wxT("An internal error has occurred in the DDEML."); break; case DMLERR_UNADVACKTIMEOUT: - err = "A request to end an advise transaction has timed out."; + err = wxT("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 = wxT("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 = wxT("Unrecognised error type."); break; } - MessageBox(NULL, (LPCSTR)err, "DDE Error", MB_OK | MB_ICONINFORMATION); + MessageBox((HWND) NULL, (LPCTSTR)err, wxT("DDE Error"), MB_OK | MB_ICONINFORMATION); } #endif - // USE_IPC + // wxUSE_IPC