CDDEConnection *CDDEClient::MakeConnection(const CString& /* host */, const CString& server_name, const CString& topic) { HSZ serviceName = DdeCreateStringHandle(DDEIdInst, (const char *)server_name, CP_WINANSI); HSZ topic_atom = DdeCreateStringHandle(DDEIdInst, (const char *)topic, CP_WINANSI); HCONV hConv = DdeConnect(DDEIdInst, serviceName, topic_atom, (PCONVCONTEXT)NULL); BOOL rt = DdeFreeStringHandle(DDEIdInst, serviceName); rt = DdeFreeStringHandle(DDEIdInst, topic_atom); if (hConv == NULL) return NULL; else { CDDEConnection *connection = OnMakeConnection(); if (connection) { connection->hConv = hConv; connection->topic_name = topic; connection->client = this; connections.AddTail(connection); // bDisconnected = true; return connection; } else return NULL; } }
wxConnectionBase *wxTCPClient::MakeConnection (const wxString& host, const wxString& serverName, const wxString& topic) { wxSockAddress *addr = GetAddressFromName(serverName, host); if ( !addr ) return NULL; wxSocketClient *client = new wxSocketClient(SCKIPC_FLAGS); wxSocketStream *stream = new wxSocketStream(*client); wxDataInputStream *data_is = new wxDataInputStream(*stream); wxDataOutputStream *data_os = new wxDataOutputStream(*stream); bool ok = client->Connect(*addr); delete addr; if ( ok ) { unsigned char msg; // Send topic name, and enquire whether this has succeeded data_os->Write8(IPC_CONNECT); data_os->WriteString(topic); msg = data_is->Read8(); // OK! Confirmation. if (msg == IPC_CONNECT) { wxTCPConnection *connection = (wxTCPConnection *)OnMakeConnection (); if (connection) { if (connection->IsKindOf(CLASSINFO(wxTCPConnection))) { connection->m_topic = topic; connection->m_sock = client; connection->m_sockstrm = stream; connection->m_codeci = data_is; connection->m_codeco = data_os; client->SetEventHandler(*gs_handler, _CLIENT_ONREQUEST_ID); client->SetClientData(connection); client->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); client->Notify(true); return connection; } else { delete connection; // and fall through to delete everything else } } } } // Something went wrong, delete everything delete data_is; delete data_os; delete stream; client->Destroy(); return NULL; }