diff --git a/src/plugins/backends/snarl/CMakeLists.txt b/src/plugins/backends/snarl/CMakeLists.txt index 392b5ae..46a5263 100644 --- a/src/plugins/backends/snarl/CMakeLists.txt +++ b/src/plugins/backends/snarl/CMakeLists.txt @@ -10,7 +10,7 @@ if(WIN32) add_library(snarl MODULE ${SNARL_SRC} ) target_link_libraries(snarl snorecore ${QT_QTCORE_LIBRARY} ) if(MINGW) - set_target_properties(snarl PROPERTIES COMPILE_FLAGS "-Wno-conversion-null") + set_target_properties(snarl PROPERTIES COMPILE_FLAGS "-Wno-conversion-null -Wno-unused") endif(MINGW) install(TARGETS snarl ${SNORE_BACKEND_INSTALL_PATH}) diff --git a/src/plugins/backends/snarl/SnarlInterface.cpp b/src/plugins/backends/snarl/SnarlInterface.cpp index 37bccfe..c61a6a9 100644 --- a/src/plugins/backends/snarl/SnarlInterface.cpp +++ b/src/plugins/backends/snarl/SnarlInterface.cpp @@ -31,6 +31,9 @@ /// ///---------------------------------------------------------------------------- /// +/// 2011-07-31 : General update to match VB6 SVN rev. 232 +/// : Added AppFlags and MessagePriority enums. +/// 2011-07-12 : MingW64 fixes by Patrick von Reth /// 2011-07-07 : Some changes to compile under VS2008 /// - Changed vector iterators to begin/end instead of cbegin/cend /// - Removed const in PairType @@ -54,11 +57,11 @@ namespace V42 { // workaround for mingw-w64 bug #ifdef __MINGW64_VERSION_MAJOR - extern "C" { + extern "C" { __declspec(dllimport) errno_t __cdecl strcpy_s(char * _Dst, size_t _SizeInBytes, const char *_Src); __declspec(dllimport) errno_t __cdecl wcscpy_s(wchar_t * _Dst, size_t _SizeInBytes, const wchar_t *_Src); - __declspec(dllimport) errno_t __cdecl strncat_s(char *_Dst, size_t _DstSizeInChars, const char *_Src, size_t _MaxCount); - } + __declspec(dllimport) errno_t __cdecl strncat_s(char *_Dst, size_t _DstSizeInChars, const char *_Src, size_t _MaxCount); + } #endif //__MINGW64_VERSION_MAJOR @@ -68,151 +71,155 @@ namespace V42 { UINT SnarlInterface::AppMsg() { - return RegisterWindowMessage(SnarlAppMsg); + return RegisterWindowMessage(SnarlAppMsg); } UINT SnarlInterface::Broadcast() { - return RegisterWindowMessage(SnarlGlobalMsg); + return RegisterWindowMessage(SnarlGlobalMsg); } LONG32 SnarlInterface::DoRequest(LPCSTR request, UINT replyTimeout) { - DWORD_PTR nResult = 0; + DWORD_PTR nResult = 0; - HWND hWnd = GetSnarlWindow(); - if (!IsWindow(hWnd)) - return -SnarlEnums::ErrorNotRunning; + HWND hWnd = GetSnarlWindow(); + if (!IsWindow(hWnd)) + return -SnarlEnums::ErrorNotRunning; - // Create COPYDATASTRUCT - COPYDATASTRUCT cds; - cds.dwData = 0x534E4C03; // "SNL",3 - cds.cbData = (DWORD)strlen(request); // No knowledge of max string lenght - cds.lpData = const_cast(request); + // Create COPYDATASTRUCT + COPYDATASTRUCT cds; + cds.dwData = 0x534E4C03; // "SNL",3 + cds.cbData = (DWORD)strlen(request); // No knowledge of max string lenght + cds.lpData = const_cast(request); - // Send message - if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)GetCurrentProcessId(), (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, replyTimeout, &nResult) == 0) - { - DWORD nError = GetLastError(); - if (nError == ERROR_TIMEOUT) - nResult = -SnarlEnums::ErrorTimedOut; - else - nResult = -SnarlEnums::ErrorFailed; - } + // Send message + if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)GetCurrentProcessId(), (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, replyTimeout, &nResult) == 0) + { + // Handle error + DWORD nError = GetLastError(); + LONG32 errorResult = 0; + if (nError == ERROR_TIMEOUT) + errorResult = -SnarlEnums::ErrorTimedOut; + else + errorResult = -SnarlEnums::ErrorFailed; - return (LONG32)nResult; + return errorResult; + } + else + return (LONG32)nResult; } LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout) { - LONG32 nResult = 0; + LONG32 nResult = 0; - // Convert to UTF8 - LPSTR utf8Request = WideToUTF8(request); - if (utf8Request == NULL) - return -SnarlEnums::ErrorCppInterface; + // Convert to UTF8 + LPSTR utf8Request = WideToUTF8(request); + if (utf8Request == NULL) + return -SnarlEnums::ErrorCppInterface; - nResult = DoRequest(utf8Request, replyTimeout); + nResult = DoRequest(utf8Request, replyTimeout); - // Cleanup and return result - FreeString(utf8Request); - return nResult; + // Cleanup and return result + FreeString(utf8Request); + return nResult; } - std::basic_string& SnarlInterface::Escape(std::basic_string& str) { - std::basic_string::size_type strLength = str.length(); - for (std::basic_string::size_type i = 0; i < strLength; ++i) - { - if (str.at(i) == '=') { - str.insert(++i, "="); - ++strLength; - } - else if (str[i] == '&') { - str.insert(++i, "&"); - ++strLength; - } - } + std::basic_string::size_type strLength = str.length(); + for (std::basic_string::size_type i = 0; i < strLength; ++i) + { + if (str.at(i) == '=') { + str.insert(++i, "="); + ++strLength; + } + else if (str[i] == '&') { + str.insert(++i, "&"); + ++strLength; + } + } - return str; + return str; } std::basic_string& SnarlInterface::Escape(std::basic_string& str) { - std::basic_string::size_type strLength = str.length(); - for (std::basic_string::size_type i = 0; i < strLength; ++i) - { - if (str.at(i) == L'=') { - str.insert(++i, L"="); - ++strLength; - } - else if (str[i] == L'&') { - str.insert(++i, L"&"); - ++strLength; - } - } + std::basic_string::size_type strLength = str.length(); + for (std::basic_string::size_type i = 0; i < strLength; ++i) + { + if (str.at(i) == L'=') { + str.insert(++i, L"="); + ++strLength; + } + else if (str[i] == L'&') { + str.insert(++i, L"&"); + ++strLength; + } + } - return str; + return str; } LPCTSTR SnarlInterface::GetAppPath() { - HWND hWnd = GetSnarlWindow(); - if (hWnd) - { - HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL); - if (hWndPath) - { - TCHAR strTmp[MAX_PATH] = {0}; - int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH-1); - if (nReturn > 0) { - TCHAR* strReturn = AllocateString(nReturn + 1); - _tcsncpy(strReturn, strTmp, nReturn + 1); - strReturn[nReturn] = 0; - return strReturn; - } - } - } + HWND hWnd = GetSnarlWindow(); + if (hWnd) + { + HWND hWndPath = FindWindowEx(hWnd, NULL, _T("static"), NULL); + if (hWndPath) + { + TCHAR strTmp[MAX_PATH] = {0}; + int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH-1); + if (nReturn > 0) { + TCHAR* strReturn = AllocateString(nReturn + 1); + _tcsncpy(strReturn, strTmp, nReturn + 1); + strReturn[nReturn] = 0; + return strReturn; + } + } + } - return NULL; + return NULL; } LPCTSTR SnarlInterface::GetIconsPath() { - TCHAR* szIconPath = NULL; - LPCTSTR szPath = GetAppPath(); - if (!szPath) - return NULL; + TCHAR* szIconPath = NULL; + LPCTSTR szPath = GetAppPath(); + if (!szPath) + return NULL; - size_t nLen = 0; - if (nLen = _tcsnlen(szPath, MAX_PATH)) - { - nLen += 10 + 1; // etc\\icons\\ + NULL - szIconPath = AllocateString(nLen); + size_t nLen = 0; + nLen = _tcsnlen(szPath, MAX_PATH); + if (nLen > 0) + { + nLen += 10 + 1; // etc\\icons\\ + NULL + szIconPath = AllocateString(nLen); - _tcsncpy(szIconPath, szPath, nLen); - _tcsncat(szIconPath, _T("etc\\icons\\"), nLen); - } - - FreeString(szPath); + _tcsncpy(szIconPath, szPath, nLen); + _tcsncat(szIconPath, _T("etc\\icons\\"), nLen); + } - return szIconPath; + FreeString(szPath); + + return szIconPath; } HWND SnarlInterface::GetSnarlWindow() { - return FindWindow(SnarlWindowClass, SnarlWindowTitle);; + return FindWindow(SnarlWindowClass, SnarlWindowTitle);; } LONG32 SnarlInterface::GetVersion() { - return DoRequest(Requests::VersionA()); + return DoRequest(Requests::VersionA()); } BOOL SnarlInterface::IsSnarlRunning() { - return IsWindow(GetSnarlWindow()); + return IsWindow(GetSnarlWindow()); } @@ -221,480 +228,479 @@ BOOL SnarlInterface::IsSnarlRunning() // -------------------------------------------------------------------------------------------- SnarlInterface::SnarlInterface() - : appToken(0), lastMsgToken(0), szPasswordA(NULL), szPasswordW(NULL) + : appToken(0), lastMsgToken(0), szPasswordA(NULL), szPasswordW(NULL) { } SnarlInterface::~SnarlInterface() { - delete [] szPasswordA; - delete [] szPasswordW; + delete [] szPasswordA; + delete [] szPasswordW; } //--------------------------------------------------------------------------------------------- LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd) { - // addaction?[token=|app-sig=&uid=][&password=]&label=