+ case XTYP_CONNECT:
+ {
+ wxString topic = DDEStringFromAtom(hsz1),
+ srv = DDEStringFromAtom(hsz2);
+ wxDDEServer *server = DDEFindServer(srv);
+ if (server)
+ {
+ wxDDEConnection *connection =
+ (wxDDEConnection*) server->OnAcceptConnection(topic);
+ if (connection)
+ {
+ connection->m_server = server;
+ server->GetConnections().Append(connection);
+ connection->m_hConv = 0;
+ connection->m_topicName = topic;
+ DDECurrentlyConnecting = connection;
+ return (DDERETURN)(DWORD)true;
+ }
+ }
+ break;
+ }
+
+ case XTYP_CONNECT_CONFIRM:
+ {
+ if (DDECurrentlyConnecting)
+ {
+ DDECurrentlyConnecting->m_hConv = (WXHCONV) hConv;
+ DDECurrentlyConnecting = NULL;
+ return (DDERETURN)(DWORD)true;
+ }
+ break;
+ }
+
+ case XTYP_DISCONNECT:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+ if (connection)
+ {
+ connection->SetConnected( false );
+ if (connection->OnDisconnect())
+ {
+ DDEDeleteConnection(hConv); // Delete mapping: hConv => connection
+ return (DDERETURN)(DWORD)true;
+ }
+ }
+ break;
+ }
+
+ case XTYP_EXECUTE:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ DWORD len = DdeGetData(hData, NULL, 0, 0);
+
+ void *data = connection->GetBufferAtLeast(len);
+ wxASSERT_MSG(data != NULL,
+ wxT("Buffer too small in _DDECallback (XTYP_EXECUTE)") );
+
+ DdeGetData(hData, (LPBYTE)data, len, 0);
+
+ DdeFreeDataHandle(hData);
+
+ // XTYP_EXECUTE can be used for text only and the text is
+ // always in ANSI format for ANSI build and Unicode format
+ // in Unicode build
+ #if wxUSE_UNICODE
+ wFmt = wxIPC_UNICODETEXT;
+ #else
+ wFmt = wxIPC_TEXT;
+ #endif
+
+ if ( connection->OnExecute(connection->m_topicName,
+ data,
+ (int)len,
+ (wxIPCFormat)wFmt) )
+ {
+ return (DDERETURN)(DWORD)DDE_FACK;
+ }
+ }
+
+ return (DDERETURN)DDE_FNOTPROCESSED;
+ }
+
+ case XTYP_REQUEST:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ wxString item_name = DDEStringFromAtom(hsz2);
+
+ size_t user_size = wxNO_LEN;
+ const void *data = connection->OnRequest(connection->m_topicName,
+ item_name,
+ &user_size,
+ (wxIPCFormat)wFmt);
+ if (data)
+ {
+ if (user_size == wxNO_LEN)
+ switch (wFmt)
+ {
+ case wxIPC_TEXT:
+ case wxIPC_UTF8TEXT:
+ user_size = strlen((const char*)data) + 1; // includes final NUL
+ break;
+ case wxIPC_UNICODETEXT:
+ user_size = (wcslen((const wchar_t*)data) + 1) * sizeof(wchar_t); // includes final NUL
+ break;
+ default:
+ user_size = 0;
+ }
+
+ HDDEDATA handle = DdeCreateDataHandle(DDEIdInst,
+ (LPBYTE)data,
+ user_size,
+ 0,
+ hsz2,
+ wFmt,
+ 0);
+ return (DDERETURN)handle;
+ }
+ }
+ break;
+ }
+
+ case XTYP_POKE:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ wxString item_name = DDEStringFromAtom(hsz2);
+
+ DWORD len = DdeGetData(hData, NULL, 0, 0);
+
+ void *data = connection->GetBufferAtLeast(len);
+ wxASSERT_MSG(data != NULL,
+ wxT("Buffer too small in _DDECallback (XTYP_POKE)") );
+
+ DdeGetData(hData, (LPBYTE)data, len, 0);
+
+ DdeFreeDataHandle(hData);
+
+ connection->OnPoke(connection->m_topicName,
+ item_name,
+ data,
+ (int)len,
+ (wxIPCFormat) wFmt);
+
+ return (DDERETURN)DDE_FACK;
+ }
+ else
+ {
+ return (DDERETURN)DDE_FNOTPROCESSED;
+ }
+ }
+
+ case XTYP_ADVSTART:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ wxString item_name = DDEStringFromAtom(hsz2);
+
+ return (DDERETURN)connection->
+ OnStartAdvise(connection->m_topicName, item_name);
+ }
+
+ break;
+ }
+
+ case XTYP_ADVSTOP:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ wxString item_name = DDEStringFromAtom(hsz2);
+
+ return (DDERETURN)connection->
+ OnStopAdvise(connection->m_topicName, item_name);
+ }
+
+ break;
+ }
+
+ case XTYP_ADVREQ:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection && connection->m_sendingData)
+ {
+ HDDEDATA data = DdeCreateDataHandle
+ (
+ DDEIdInst,
+ (LPBYTE)connection->m_sendingData,
+ connection->m_dataSize,
+ 0,
+ hsz2,
+ connection->m_dataType,
+ 0
+ );
+
+ connection->m_sendingData = NULL;
+
+ return (DDERETURN)data;
+ }
+
+ break;
+ }
+
+ case XTYP_ADVDATA:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ wxString item_name = DDEStringFromAtom(hsz2);
+
+ DWORD len = DdeGetData(hData, NULL, 0, 0);
+
+ void *data = connection->GetBufferAtLeast(len);
+ wxASSERT_MSG(data != NULL,
+ wxT("Buffer too small in _DDECallback (XTYP_ADVDATA)") );
+
+ DdeGetData(hData, (LPBYTE)data, len, 0);
+
+ DdeFreeDataHandle(hData);
+ if ( connection->OnAdvise(connection->m_topicName,
+ item_name,
+ data,
+ (int)len,
+ (wxIPCFormat) wFmt) )
+ {
+ return (DDERETURN)(DWORD)DDE_FACK;
+ }
+ }
+
+ return (DDERETURN)DDE_FNOTPROCESSED;
+ }