//-------------------------------------------------------------- /// Binds to ip address and port /// \param s Input socket /// \return Bound socket address or 0 for failure to bind //-------------------------------------------------------------- static NetSocket* WebServerBind(NetSocket* s) { if (s->Bind((u_short)s_dwPort) == false) { if (s_dwPort == 80) { MessageBoxError("Can't listen on port 80, this port is probably being used by another application.\n\nCommon apps that use this port are:\n 1 ) Skype\n 2 ) a local webserver\n\nPlease use the –port=<arg> command-line option to use an alternate port.\nRemember that you'll have to use include the new port number when connecting to the server.\n"); } else { MessageBoxError(FormatText("Port %u is already in use by another application.", s_dwPort)); } s->close(); return (0); } return s; }
BOOL CNetSendProp::OnReceiveMessage ( IN HWND hwnd, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam ) { HRESULT hr ; switch (uMsg) { case WM_INITDIALOG: { ASSERT (m_hwnd == NULL) ; m_hwnd = hwnd ; return TRUE ; } case WM_DESTROY : { m_hwnd = NULL ; break ; } case WM_COMMAND: { switch (LOWORD (wParam)) { case IDC_SAVE : hr = OnSave_ () ; if (FAILED (hr)) { MessageBoxError (TEXT("Failed to Save"), TEXT("The returned error code is %08xh"), hr) ; } break ; } ; return TRUE ; } } return CBasePropertyPage::OnReceiveMessage ( hwnd, uMsg, wParam, lParam ) ; }
static void CALLBACK HookTaskbar(HWND taskbar, VOID* unused) { ClockWindow* multiClock = new ClockWindow(); HWND window = multiClock->Create(taskbar, nullptr, nullptr, WS_CHILD | WS_DISABLED, WS_EX_LAYERED | WS_EX_TRANSPARENT, 0U, nullptr); if (window == nullptr) { #if _DEBUG DWORD error = GetLastError(); MessageBoxError(error); #endif delete multiClock; return; } multiClock->RepositionIn(taskbar); multiClock->ShowWindow(SW_SHOW); multiClock->Refresh(true); }
//----------------------------------------------------------------------------- /// Create a streaming socket to communicate between the plugin and the /// webserver. This avoids the duplication. A new thread is created each time a /// streaming request comes in. This is because the client socket changes so /// this change will need propagating to the thread so it knows where to send /// the requests back to. /// The streaming socket uses the next port after the web server port, so if /// the webserver is using port 8080, the streaming port will be 8081 /// \param pRequestHeader the request header to pass to the plugin /// \param pClientSocket the socket used for communication /// \return true is successful, false otherwise //----------------------------------------------------------------------------- bool ProcessTracker::CreateStreamSocket(HTTPRequestHeader* pRequestHeader, NetSocket* pClientSocket) { CloseStreamThread(); CloseStreamSockets(); // figure out which port to use. For now, use the port the web server is using + 1 DWORD port = GetWebServerPort() + 1; pRequestHeader->GetHeaderData()->dwPort = port; // no other threads will be running now so this should be safe m_serverSocket = NetSocket::Create(); if (m_serverSocket == NULL) { Log(logERROR, "Error creating streamSocket\n"); return false; } // try and bind to the streaming port if (m_serverSocket->Bind((u_short)port) == false) { MessageBoxError(FormatText("Port %u is already in use by another application.", port)); m_serverSocket->close(); return false; } // try to listen next if (m_serverSocket->Listen() == false) { m_serverSocket->close(); return false; } m_streamThread = ForkAndWaitForPluginStream(pClientSocket); return true; }