1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/dde.cpp
3 // Purpose: DDE classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
32 #include "wx/hashmap.h"
33 #include "wx/module.h"
38 #include "wx/buffer.h"
39 #include "wx/strconv.h"
41 #include "wx/msw/private.h"
46 // ----------------------------------------------------------------------------
47 // macros and constants
48 // ----------------------------------------------------------------------------
53 #define _EXPORT _export
57 #define DDE_CP CP_WINUNICODE
59 #define DDE_CP CP_WINANSI
62 #define GetHConv() ((HCONV)m_hConv)
64 // default timeout for DDE operations (5sec)
65 #define DDE_TIMEOUT 5000
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 static wxDDEConnection
*DDEFindConnection(HCONV hConv
);
72 static void DDEDeleteConnection(HCONV hConv
);
73 static wxDDEServer
*DDEFindServer(const wxString
& s
);
75 extern "C" HDDEDATA EXPENTRY _EXPORT
_DDECallback(WORD wType
,
84 // Add topic name to atom table before using in conversations
85 static HSZ
DDEAddAtom(const wxString
& string
);
86 static HSZ
DDEGetAtom(const wxString
& string
);
89 static HSZ
DDEAtomFromString(const wxString
& s
);
90 static wxString
DDEStringFromAtom(HSZ hsz
);
91 static void DDEFreeString(HSZ hsz
);
94 static wxString
DDEGetErrorMsg(UINT error
);
95 static void DDELogError(const wxString
& s
, UINT error
= DMLERR_NO_ERROR
);
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 WX_DECLARE_STRING_HASH_MAP( HSZ
, wxAtomMap
);
103 static DWORD DDEIdInst
= 0L;
104 static wxDDEConnection
*DDECurrentlyConnecting
= NULL
;
105 static wxAtomMap wxAtomTable
;
107 #include "wx/listimpl.cpp"
109 WX_DEFINE_LIST(wxDDEClientList
)
110 WX_DEFINE_LIST(wxDDEServerList
)
111 WX_DEFINE_LIST(wxDDEConnectionList
)
113 static wxDDEClientList wxDDEClientObjects
;
114 static wxDDEServerList wxDDEServerObjects
;
116 static bool DDEInitialized
= false;
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 // A module to allow DDE cleanup without calling these functions
123 // from app.cpp or from the user's application.
125 class wxDDEModule
: public wxModule
129 bool OnInit() { return true; }
130 void OnExit() { wxDDECleanUp(); }
133 DECLARE_DYNAMIC_CLASS(wxDDEModule
)
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 IMPLEMENT_DYNAMIC_CLASS(wxDDEServer
, wxServerBase
)
141 IMPLEMENT_DYNAMIC_CLASS(wxDDEClient
, wxClientBase
)
142 IMPLEMENT_DYNAMIC_CLASS(wxDDEConnection
, wxConnectionBase
)
143 IMPLEMENT_DYNAMIC_CLASS(wxDDEModule
, wxModule
)
145 // ============================================================================
147 // ============================================================================
149 // ----------------------------------------------------------------------------
150 // initialization and cleanup
151 // ----------------------------------------------------------------------------
153 extern void wxDDEInitialize()
155 if ( !DDEInitialized
)
157 // Should insert filter flags
158 PFNCALLBACK callback
= (PFNCALLBACK
)
159 MakeProcInstance((FARPROC
)_DDECallback
, wxGetInstance());
160 UINT rc
= DdeInitialize(&DDEIdInst
, callback
, APPCLASS_STANDARD
, 0L);
161 if ( rc
!= DMLERR_NO_ERROR
)
163 DDELogError(wxT("Failed to initialize DDE"), rc
);
167 DDEInitialized
= true;
174 // deleting them later won't work as DDE won't be initialized any more
175 wxASSERT_MSG( wxDDEServerObjects
.empty() &&
176 wxDDEClientObjects
.empty(),
177 wxT("all DDE objects should be deleted by now") );
181 if ( DDEIdInst
!= 0 )
183 DdeUninitialize(DDEIdInst
);
188 // ----------------------------------------------------------------------------
189 // functions working with the global connection list(s)
190 // ----------------------------------------------------------------------------
192 // Global find connection
193 static wxDDEConnection
*DDEFindConnection(HCONV hConv
)
195 wxDDEServerList::compatibility_iterator serverNode
= wxDDEServerObjects
.GetFirst();
196 wxDDEConnection
*found
= NULL
;
197 while (serverNode
&& !found
)
199 wxDDEServer
*object
= serverNode
->GetData();
200 found
= object
->FindConnection((WXHCONV
) hConv
);
201 serverNode
= serverNode
->GetNext();
209 wxDDEClientList::compatibility_iterator clientNode
= wxDDEClientObjects
.GetFirst();
210 while (clientNode
&& !found
)
212 wxDDEClient
*object
= clientNode
->GetData();
213 found
= object
->FindConnection((WXHCONV
) hConv
);
214 clientNode
= clientNode
->GetNext();
219 // Global delete connection
220 static void DDEDeleteConnection(HCONV hConv
)
222 wxDDEServerList::compatibility_iterator serverNode
= wxDDEServerObjects
.GetFirst();
224 while (serverNode
&& !found
)
226 wxDDEServer
*object
= serverNode
->GetData();
227 found
= object
->DeleteConnection((WXHCONV
) hConv
);
228 serverNode
= serverNode
->GetNext();
235 wxDDEClientList::compatibility_iterator clientNode
= wxDDEClientObjects
.GetFirst();
236 while (clientNode
&& !found
)
238 wxDDEClient
*object
= clientNode
->GetData();
239 found
= object
->DeleteConnection((WXHCONV
) hConv
);
240 clientNode
= clientNode
->GetNext();
244 // Find a server from a service name
245 static wxDDEServer
*DDEFindServer(const wxString
& s
)
247 wxDDEServerList::compatibility_iterator node
= wxDDEServerObjects
.GetFirst();
248 wxDDEServer
*found
= NULL
;
249 while (node
&& !found
)
251 wxDDEServer
*object
= node
->GetData();
253 if (object
->GetServiceName() == s
)
259 node
= node
->GetNext();
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
270 wxDDEServer::wxDDEServer()
274 wxDDEServerObjects
.Append(this);
277 bool wxDDEServer::Create(const wxString
& server
)
279 m_serviceName
= server
;
281 HSZ hsz
= DDEAtomFromString(server
);
289 bool success
= (DdeNameService(DDEIdInst
, hsz
, (HSZ
) NULL
, DNS_REGISTER
)
294 DDELogError(wxString::Format(_("Failed to register DDE server '%s'"),
303 wxDDEServer::~wxDDEServer()
305 if ( !m_serviceName
.empty() )
307 HSZ hsz
= DDEAtomFromString(m_serviceName
);
311 if ( !DdeNameService(DDEIdInst
, hsz
,
312 (HSZ
) NULL
, DNS_UNREGISTER
) )
314 DDELogError(wxString::Format(
315 _("Failed to unregister DDE server '%s'"),
316 m_serviceName
.c_str()));
323 wxDDEServerObjects
.DeleteObject(this);
325 wxDDEConnectionList::compatibility_iterator node
= m_connections
.GetFirst();
328 wxDDEConnection
*connection
= node
->GetData();
329 wxDDEConnectionList::compatibility_iterator next
= node
->GetNext();
330 connection
->OnDisconnect(); // May delete the node implicitly
334 // If any left after this, delete them
335 node
= m_connections
.GetFirst();
338 wxDDEConnection
*connection
= node
->GetData();
339 wxDDEConnectionList::compatibility_iterator next
= node
->GetNext();
345 wxConnectionBase
*wxDDEServer::OnAcceptConnection(const wxString
& /* topic */)
347 return new wxDDEConnection
;
350 wxDDEConnection
*wxDDEServer::FindConnection(WXHCONV conv
)
352 wxDDEConnectionList::compatibility_iterator node
= m_connections
.GetFirst();
353 wxDDEConnection
*found
= NULL
;
354 while (node
&& !found
)
356 wxDDEConnection
*connection
= node
->GetData();
357 if (connection
->m_hConv
== conv
)
359 else node
= node
->GetNext();
364 // Only delete the entry in the map, not the actual connection
365 bool wxDDEServer::DeleteConnection(WXHCONV conv
)
367 wxDDEConnectionList::compatibility_iterator node
= m_connections
.GetFirst();
370 wxDDEConnection
*connection
= node
->GetData();
371 if (connection
->m_hConv
== conv
)
373 m_connections
.Erase(node
);
378 node
= node
->GetNext();
384 // ----------------------------------------------------------------------------
386 // ----------------------------------------------------------------------------
388 wxDDEClient::wxDDEClient()
392 wxDDEClientObjects
.Append(this);
395 wxDDEClient::~wxDDEClient()
397 wxDDEClientObjects
.DeleteObject(this);
398 wxDDEConnectionList::compatibility_iterator node
= m_connections
.GetFirst();
401 wxDDEConnection
*connection
= node
->GetData();
402 delete connection
; // Deletes the node implicitly (see ~wxDDEConnection)
403 node
= m_connections
.GetFirst();
407 bool wxDDEClient::ValidHost(const wxString
& /* host */)
412 wxConnectionBase
*wxDDEClient::MakeConnection(const wxString
& WXUNUSED(host
),
413 const wxString
& server
,
414 const wxString
& topic
)
416 HSZ hszServer
= DDEAtomFromString(server
);
424 HSZ hszTopic
= DDEAtomFromString(topic
);
428 DDEFreeString(hszServer
);
433 HCONV hConv
= ::DdeConnect(DDEIdInst
, hszServer
, hszTopic
,
434 (PCONVCONTEXT
) NULL
);
436 DDEFreeString(hszServer
);
437 DDEFreeString(hszTopic
);
442 DDELogError( wxString::Format(
443 _("Failed to create connection to server '%s' on topic '%s'"),
444 server
.c_str(), topic
.c_str()) );
448 wxDDEConnection
*connection
= (wxDDEConnection
*) OnMakeConnection();
451 connection
->m_hConv
= (WXHCONV
) hConv
;
452 connection
->m_topicName
= topic
;
453 connection
->m_client
= this;
454 m_connections
.Append(connection
);
462 wxConnectionBase
*wxDDEClient::OnMakeConnection()
464 return new wxDDEConnection
;
467 wxDDEConnection
*wxDDEClient::FindConnection(WXHCONV conv
)
469 wxDDEConnectionList::compatibility_iterator node
= m_connections
.GetFirst();
470 wxDDEConnection
*found
= NULL
;
471 while (node
&& !found
)
473 wxDDEConnection
*connection
= node
->GetData();
474 if (connection
->m_hConv
== conv
)
476 else node
= node
->GetNext();
481 // Only delete the entry in the map, not the actual connection
482 bool wxDDEClient::DeleteConnection(WXHCONV conv
)
484 wxDDEConnectionList::compatibility_iterator node
= m_connections
.GetFirst();
487 wxDDEConnection
*connection
= node
->GetData();
488 if (connection
->m_hConv
== conv
)
490 m_connections
.Erase(node
);
493 else node
= node
->GetNext();
498 // ----------------------------------------------------------------------------
500 // ----------------------------------------------------------------------------
502 wxDDEConnection::wxDDEConnection(void *buffer
, size_t size
)
503 : wxConnectionBase(buffer
, size
)
509 m_sendingData
= NULL
;
512 wxDDEConnection::wxDDEConnection()
516 m_sendingData
= NULL
;
521 wxDDEConnection::~wxDDEConnection()
525 m_server
->GetConnections().DeleteObject(this);
527 m_client
->GetConnections().DeleteObject(this);
530 // Calls that CLIENT can make
531 bool wxDDEConnection::Disconnect()
533 if ( !GetConnected() )
536 DDEDeleteConnection(GetHConv());
538 bool ok
= DdeDisconnect(GetHConv()) != 0;
541 DDELogError(wxT("Failed to disconnect from DDE server gracefully"));
544 SetConnected( false ); // so we don't try and disconnect again
550 wxDDEConnection::DoExecute(const void *data
, size_t size
, wxIPCFormat format
)
552 wxCHECK_MSG( format
== wxIPC_TEXT
||
553 format
== wxIPC_UTF8TEXT
||
554 format
== wxIPC_UNICODETEXT
,
556 wxT("wxDDEServer::Execute() supports only text data") );
558 wxMemoryBuffer buffer
;
559 LPBYTE realData
= NULL
;
561 wxMBConv
*conv
= NULL
;
563 // Windows only supports either ANSI or UTF-16 format depending on the
564 // build, so we need to convert the data if it doesn't use it already
566 if ( format
== wxIPC_TEXT
)
570 else if ( format
== wxIPC_UTF8TEXT
)
574 else // no conversion necessary for wxIPC_UNICODETEXT
576 realData
= (LPBYTE
)data
;
582 const char * const text
= (const char *)data
;
583 const size_t len
= size
/sizeof(char);
585 realSize
= conv
->ToWChar(NULL
, 0, text
, len
);
586 if ( realSize
== wxCONV_FAILED
)
589 realData
= (LPBYTE
)buffer
.GetWriteBuf(realSize
*sizeof(wchar_t));
593 realSize
= conv
->ToWChar((wchar_t *)realData
, realSize
, text
, len
);
594 if ( realSize
== wxCONV_FAILED
)
597 #else // !wxUSE_UNICODE
598 if ( format
== wxIPC_UNICODETEXT
)
602 else if ( format
== wxIPC_UTF8TEXT
)
604 // we could implement this in theory but it's not obvious how to pass
605 // the format information and, basically, why bother -- just use
607 wxFAIL_MSG( wxT("UTF-8 text not supported in ANSI build") );
611 else // don't convert wxIPC_TEXT
613 realData
= (LPBYTE
)data
;
619 const wchar_t * const wtext
= (const wchar_t *)data
;
620 const size_t len
= size
/sizeof(wchar_t);
622 realSize
= conv
->FromWChar(NULL
, 0, wtext
, len
);
623 if ( realSize
== wxCONV_FAILED
)
626 realData
= (LPBYTE
)buffer
.GetWriteBuf(realSize
*sizeof(char));
630 realSize
= conv
->FromWChar((char*)realData
, realSize
, wtext
, len
);
631 if ( realSize
== wxCONV_FAILED
)
634 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
637 bool ok
= DdeClientTransaction(realData
,
638 realSize
*sizeof(wxChar
),
641 // MSDN: if the transaction specified by
642 // the wType parameter does not pass data
643 // or is XTYP_EXECUTE, wFmt should be zero.
651 DDELogError(wxT("DDE execute request failed"));
657 const void *wxDDEConnection::Request(const wxString
& item
, size_t *size
, wxIPCFormat format
)
661 HSZ atom
= DDEGetAtom(item
);
663 HDDEDATA returned_data
= DdeClientTransaction(NULL
, 0,
669 if ( !returned_data
)
671 DDELogError(wxT("DDE data request failed"));
676 DWORD len
= DdeGetData(returned_data
, NULL
, 0, 0);
678 void *data
= GetBufferAtLeast(len
);
679 wxASSERT_MSG(data
!= NULL
,
680 wxT("Buffer too small in wxDDEConnection::Request") );
681 (void) DdeGetData(returned_data
, (LPBYTE
)data
, len
, 0);
683 (void) DdeFreeDataHandle(returned_data
);
691 bool wxDDEConnection::DoPoke(const wxString
& item
, const void *data
, size_t size
, wxIPCFormat format
)
695 HSZ item_atom
= DDEGetAtom(item
);
696 bool ok
= DdeClientTransaction((LPBYTE
)data
,
705 DDELogError(_("DDE poke request failed"));
711 bool wxDDEConnection::StartAdvise(const wxString
& item
)
714 HSZ atom
= DDEGetAtom(item
);
716 bool ok
= DdeClientTransaction(NULL
, 0,
724 DDELogError(_("Failed to establish an advise loop with DDE server"));
730 bool wxDDEConnection::StopAdvise(const wxString
& item
)
733 HSZ atom
= DDEGetAtom(item
);
735 bool ok
= DdeClientTransaction(NULL
, 0,
743 DDELogError(_("Failed to terminate the advise loop with DDE server"));
749 // Calls that SERVER can make
750 bool wxDDEConnection::DoAdvise(const wxString
& item
,
755 HSZ item_atom
= DDEGetAtom(item
);
756 HSZ topic_atom
= DDEGetAtom(m_topicName
);
757 m_sendingData
= data
; // mrf: potential for scope problems here?
759 // wxIPC_PRIVATE does not succeed, so use text instead
760 m_dataType
= format
== wxIPC_PRIVATE
? wxIPC_TEXT
: format
;
762 bool ok
= DdePostAdvise(DDEIdInst
, topic_atom
, item_atom
) != 0;
765 DDELogError(_("Failed to send DDE advise notification"));
771 // ----------------------------------------------------------------------------
773 // ----------------------------------------------------------------------------
775 #define DDERETURN HDDEDATA
777 HDDEDATA EXPENTRY _EXPORT
778 _DDECallback(WORD wType
,
784 DWORD
WXUNUSED(lData1
),
785 DWORD
WXUNUSED(lData2
))
791 wxString topic
= DDEStringFromAtom(hsz1
),
792 srv
= DDEStringFromAtom(hsz2
);
793 wxDDEServer
*server
= DDEFindServer(srv
);
796 wxDDEConnection
*connection
=
797 (wxDDEConnection
*) server
->OnAcceptConnection(topic
);
800 connection
->m_server
= server
;
801 server
->GetConnections().Append(connection
);
802 connection
->m_hConv
= 0;
803 connection
->m_topicName
= topic
;
804 DDECurrentlyConnecting
= connection
;
805 return (DDERETURN
)(DWORD
)true;
811 case XTYP_CONNECT_CONFIRM
:
813 if (DDECurrentlyConnecting
)
815 DDECurrentlyConnecting
->m_hConv
= (WXHCONV
) hConv
;
816 DDECurrentlyConnecting
= NULL
;
817 return (DDERETURN
)(DWORD
)true;
822 case XTYP_DISCONNECT
:
824 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
827 connection
->SetConnected( false );
828 if (connection
->OnDisconnect())
830 DDEDeleteConnection(hConv
); // Delete mapping: hConv => connection
831 return (DDERETURN
)(DWORD
)true;
839 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
843 DWORD len
= DdeGetData(hData
, NULL
, 0, 0);
845 void *data
= connection
->GetBufferAtLeast(len
);
846 wxASSERT_MSG(data
!= NULL
,
847 wxT("Buffer too small in _DDECallback (XTYP_EXECUTE)") );
849 DdeGetData(hData
, (LPBYTE
)data
, len
, 0);
851 DdeFreeDataHandle(hData
);
853 // XTYP_EXECUTE can be used for text only and the text is
854 // always in ANSI format for ANSI build and Unicode format
857 wFmt
= wxIPC_UNICODETEXT
;
862 if ( connection
->OnExecute(connection
->m_topicName
,
867 return (DDERETURN
)(DWORD
)DDE_FACK
;
871 return (DDERETURN
)DDE_FNOTPROCESSED
;
876 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
880 wxString item_name
= DDEStringFromAtom(hsz2
);
882 size_t user_size
= wxNO_LEN
;
883 const void *data
= connection
->OnRequest(connection
->m_topicName
,
889 if (user_size
== wxNO_LEN
)
894 user_size
= strlen((const char*)data
) + 1; // includes final NUL
896 case wxIPC_UNICODETEXT
:
897 user_size
= (wcslen((const wchar_t*)data
) + 1) * sizeof(wchar_t); // includes final NUL
903 HDDEDATA handle
= DdeCreateDataHandle(DDEIdInst
,
910 return (DDERETURN
)handle
;
918 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
922 wxString item_name
= DDEStringFromAtom(hsz2
);
924 DWORD len
= DdeGetData(hData
, NULL
, 0, 0);
926 void *data
= connection
->GetBufferAtLeast(len
);
927 wxASSERT_MSG(data
!= NULL
,
928 wxT("Buffer too small in _DDECallback (XTYP_POKE)") );
930 DdeGetData(hData
, (LPBYTE
)data
, len
, 0);
932 DdeFreeDataHandle(hData
);
934 connection
->OnPoke(connection
->m_topicName
,
940 return (DDERETURN
)DDE_FACK
;
944 return (DDERETURN
)DDE_FNOTPROCESSED
;
950 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
954 wxString item_name
= DDEStringFromAtom(hsz2
);
956 return (DDERETURN
)connection
->
957 OnStartAdvise(connection
->m_topicName
, item_name
);
965 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
969 wxString item_name
= DDEStringFromAtom(hsz2
);
971 return (DDERETURN
)connection
->
972 OnStopAdvise(connection
->m_topicName
, item_name
);
980 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
982 if (connection
&& connection
->m_sendingData
)
984 HDDEDATA data
= DdeCreateDataHandle
987 (LPBYTE
)connection
->m_sendingData
,
988 connection
->m_dataSize
,
991 connection
->m_dataType
,
995 connection
->m_sendingData
= NULL
;
997 return (DDERETURN
)data
;
1005 wxDDEConnection
*connection
= DDEFindConnection(hConv
);
1009 wxString item_name
= DDEStringFromAtom(hsz2
);
1011 DWORD len
= DdeGetData(hData
, NULL
, 0, 0);
1013 void *data
= connection
->GetBufferAtLeast(len
);
1014 wxASSERT_MSG(data
!= NULL
,
1015 wxT("Buffer too small in _DDECallback (XTYP_ADVDATA)") );
1017 DdeGetData(hData
, (LPBYTE
)data
, len
, 0);
1019 DdeFreeDataHandle(hData
);
1020 if ( connection
->OnAdvise(connection
->m_topicName
,
1024 (wxIPCFormat
) wFmt
) )
1026 return (DDERETURN
)(DWORD
)DDE_FACK
;
1030 return (DDERETURN
)DDE_FNOTPROCESSED
;
1034 return (DDERETURN
)0;
1037 // ----------------------------------------------------------------------------
1038 // DDE strings and atoms
1039 // ----------------------------------------------------------------------------
1042 static HSZ
DDEAddAtom(const wxString
& str
)
1044 HSZ atom
= DDEAtomFromString(str
);
1045 wxAtomTable
[str
] = atom
;
1049 static HSZ
DDEGetAtom(const wxString
& str
)
1051 wxAtomMap::iterator it
= wxAtomTable
.find(str
);
1053 if (it
!= wxAtomTable
.end())
1056 return DDEAddAtom(str
);
1060 The returned handle has to be freed by the caller (using
1061 (static) DDEFreeString).
1063 static HSZ
DDEAtomFromString(const wxString
& s
)
1065 wxASSERT_MSG( DDEIdInst
, wxT("DDE not initialized") );
1067 HSZ hsz
= DdeCreateStringHandle(DDEIdInst
, (wxChar
*)s
.wx_str(), DDE_CP
);
1070 DDELogError(_("Failed to create DDE string"));
1076 static wxString
DDEStringFromAtom(HSZ hsz
)
1078 // all DDE strings are normally limited to 255 bytes
1079 static const size_t len
= 256;
1082 (void)DdeQueryString(DDEIdInst
, hsz
, wxStringBuffer(s
, len
), len
, DDE_CP
);
1087 static void DDEFreeString(HSZ hsz
)
1089 // DS: Failure to free a string handle might indicate there's
1090 // some other severe error.
1091 bool ok
= (::DdeFreeStringHandle(DDEIdInst
, hsz
) != 0);
1092 wxASSERT_MSG( ok
, wxT("Failed to free DDE string handle") );
1096 // ----------------------------------------------------------------------------
1098 // ----------------------------------------------------------------------------
1100 static void DDELogError(const wxString
& s
, UINT error
)
1104 error
= DdeGetLastError(DDEIdInst
);
1107 wxLogError(s
+ wxT(": ") + DDEGetErrorMsg(error
));
1110 static wxString
DDEGetErrorMsg(UINT error
)
1115 case DMLERR_NO_ERROR
:
1116 err
= _("no DDE error.");
1119 case DMLERR_ADVACKTIMEOUT
:
1120 err
= _("a request for a synchronous advise transaction has timed out.");
1123 err
= _("the response to the transaction caused the DDE_FBUSY bit to be set.");
1125 case DMLERR_DATAACKTIMEOUT
:
1126 err
= _("a request for a synchronous data transaction has timed out.");
1128 case DMLERR_DLL_NOT_INITIALIZED
:
1129 err
= _("a DDEML function was called without first calling the DdeInitialize function,\nor an invalid instance identifier\nwas passed to a DDEML function.");
1131 case DMLERR_DLL_USAGE
:
1132 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.");
1134 case DMLERR_EXECACKTIMEOUT
:
1135 err
= _("a request for a synchronous execute transaction has timed out.");
1137 case DMLERR_INVALIDPARAMETER
:
1138 err
= _("a parameter failed to be validated by the DDEML.");
1140 case DMLERR_LOW_MEMORY
:
1141 err
= _("a DDEML application has created a prolonged race condition.");
1143 case DMLERR_MEMORY_ERROR
:
1144 err
= _("a memory allocation failed.");
1146 case DMLERR_NO_CONV_ESTABLISHED
:
1147 err
= _("a client's attempt to establish a conversation has failed.");
1149 case DMLERR_NOTPROCESSED
:
1150 err
= _("a transaction failed.");
1152 case DMLERR_POKEACKTIMEOUT
:
1153 err
= _("a request for a synchronous poke transaction has timed out.");
1155 case DMLERR_POSTMSG_FAILED
:
1156 err
= _("an internal call to the PostMessage function has failed. ");
1158 case DMLERR_REENTRANCY
:
1159 err
= _("reentrancy problem.");
1161 case DMLERR_SERVER_DIED
:
1162 err
= _("a server-side transaction was attempted on a conversation\nthat was terminated by the client, or the server\nterminated before completing a transaction.");
1164 case DMLERR_SYS_ERROR
:
1165 err
= _("an internal error has occurred in the DDEML.");
1167 case DMLERR_UNADVACKTIMEOUT
:
1168 err
= _("a request to end an advise transaction has timed out.");
1170 case DMLERR_UNFOUND_QUEUE_ID
:
1171 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.");
1174 err
.Printf(_("Unknown DDE error %08x"), error
);