X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/589c1174f4dd9ccd5b7fc941e3d239888e1a8653..14619f10b0bdb630206607abd0ce0319d45e095a:/samples/ipc/server.cpp diff --git a/samples/ipc/server.cpp b/samples/ipc/server.cpp index afe890aacf..47b2d62ee6 100644 --- a/samples/ipc/server.cpp +++ b/samples/ipc/server.cpp @@ -32,7 +32,7 @@ // we're using TCP/IP or real DDE. #include "ipcsetup.h" -#if !defined(__WXMSW__) && !defined(__WXPM__) +#ifndef wxHAS_IMAGES_IN_RESOURCES #include "../sample.xpm" #endif @@ -160,11 +160,7 @@ void MyFrame::UpdateUI() void MyFrame::OnClose(wxCloseEvent& event) { - if (m_server) - { - delete m_server; - m_server = NULL; - } + wxDELETE(m_server); event.Skip(); } @@ -185,8 +181,7 @@ void MyFrame::OnStart(wxCommandEvent& WXUNUSED(event)) else { wxLogMessage("Server %s failed to start", servername); - delete m_server; - m_server = NULL; + wxDELETE(m_server); } UpdateUI(); } @@ -262,8 +257,7 @@ void MyServer::Disconnect() { if ( m_connection ) { - delete m_connection; - m_connection = NULL; + wxDELETE(m_connection); wxGetApp().GetFrame()->UpdateUI(); wxLogMessage("Disconnected client"); } @@ -324,25 +318,26 @@ MyConnection::OnRequest(const wxString& topic, { *size = 0; - wxString afterDate; + wxString s, + afterDate; if ( item.StartsWith("Date", &afterDate) ) { const wxDateTime now = wxDateTime::Now(); if ( afterDate.empty() ) { - m_requestData = now.Format(); + s = now.Format(); *size = wxNO_LEN; } else if ( afterDate == "+len" ) { - m_requestData = now.FormatTime() + " " + now.FormatDate(); - *size = strlen(m_requestData.mb_str()) + 1; + s = now.FormatTime() + " " + now.FormatDate(); + *size = strlen(s.mb_str()) + 1; } } else if ( item == "bytes[3]" ) { - m_requestData = "123"; + s = "123"; *size = 3; } @@ -352,7 +347,10 @@ MyConnection::OnRequest(const wxString& topic, return NULL; } - const void * const data = m_requestData.mb_str(); + // store the data pointer to which we return in a member variable to ensure + // that the pointer remains valid even after we return + m_requestData = s.mb_str(); + const void * const data = m_requestData; Log("OnRequest", topic, item, data, *size, format); return data; }