- wxChar topic_buf[100];
- wxChar server_buf[100];
- DdeQueryString(DDEIdInst, hsz1, (LPTSTR)topic_buf, WXSIZEOF(topic_buf),
- CP_WINANSI);
- DdeQueryString(DDEIdInst, hsz2, (LPTSTR)server_buf, WXSIZEOF(topic_buf),
- CP_WINANSI);
- wxDDEServer *server = DDEFindServer(server_buf);
- if (server)
- {
- wxDDEConnection *connection =
- (wxDDEConnection*) server->OnAcceptConnection(wxString(topic_buf));
- if (connection)
- {
- connection->m_server = server;
- server->GetConnections().Append(connection);
- connection->m_hConv = 0;
- connection->m_topicName = topic_buf;
- DDECurrentlyConnecting = connection;
- return (DDERETURN)(DWORD)TRUE;
- }
- }
- else return (DDERETURN)0;
- break;
+ 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->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,
+ (LPBYTE)connection->m_bufPtr,
+ connection->m_bufSize,
+ 0);
+ DdeFreeDataHandle(hData);
+ if ( connection->OnExecute(connection->m_topicName,
+ connection->m_bufPtr,
+ (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);
+
+ int user_size = -1;
+ char *data = connection->OnRequest(connection->m_topicName,
+ item_name,
+ &user_size,
+ (wxIPCFormat) wFmt);
+ if (data)
+ {
+ if (user_size < 0)
+ user_size = wxStrlen((wxChar*)data) + 1;
+
+ 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,
+ (LPBYTE)connection->m_bufPtr,
+ connection->m_bufSize,
+ 0);
+ DdeFreeDataHandle(hData);
+
+ connection->OnPoke(connection->m_topicName,
+ item_name,
+ (wxChar*)connection->m_bufPtr,
+ (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,
+ (LPBYTE)connection->m_bufPtr,
+ connection->m_bufSize,
+ 0);
+ DdeFreeDataHandle(hData);
+ if ( connection->OnAdvise(connection->m_topicName,
+ item_name,
+ connection->m_bufPtr,
+ (int)len,
+ (wxIPCFormat) wFmt) )
+ {
+ return (DDERETURN)(DWORD)DDE_FACK;
+ }
+ }
+
+ return (DDERETURN)DDE_FNOTPROCESSED;
+ }