+ 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);
+
+ 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);
+
+// XTYP_EXECUTE cannot be used for arbitrary data, but only for text
+ if ( connection->OnExecute(connection->m_topicName,
+ data,
+ (int)len,
+ wxIPC_TEXT ) )
+ {
+ return (DDERETURN)(DWORD)DDE_FACK;
+ }
+ }
+
+ return (DDERETURN)DDE_FNOTPROCESSED;
+ }
+
+ case XTYP_REQUEST:
+ {
+ wxDDEConnection *connection = DDEFindConnection(hConv);
+
+ if (connection)
+ {
+ wxString item_name = DDEStringFromAtom(hsz2);
+
+ int user_size = -1;
+ wxChar *data = connection->OnRequest(connection->m_topicName,
+ item_name,
+ &user_size,
+ (wxIPCFormat) wFmt);
+ if (data)
+ {
+ if (user_size < 0)
+ user_size = (wxStrlen((wxChar*)data) + 1) * sizeof(wxChar); // includes final NUL
+
+ 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);
+
+ wxChar *data = connection->GetBufferAtLeast( len );
+ wxASSERT_MSG(data != NULL,
+ _T("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);
+
+ 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,
+ data,
+ (int)len,
+ (wxIPCFormat) wFmt) )
+ {
+ return (DDERETURN)(DWORD)DDE_FACK;
+ }
+ }
+
+ return (DDERETURN)DDE_FNOTPROCESSED;
+ }