From a7c24ca48995cf2bf436156302f96b91bf135409 Mon Sep 17 00:00:00 2001 From: Goraf <22941576+Goraf@users.noreply.github.com> Date: Mon, 13 Nov 2017 15:03:31 +0100 Subject: Code modernize ... * replace 0/NULL with nullptr [using clang-tidy] --- plugins/ListeningTo/src/players/generic.cpp | 40 ++++++++++++++--------------- plugins/ListeningTo/src/players/itunes.cpp | 26 +++++++++---------- plugins/ListeningTo/src/players/player.cpp | 36 +++++++++++++------------- plugins/ListeningTo/src/players/watrack.cpp | 18 ++++++------- plugins/ListeningTo/src/players/wmp.cpp | 34 ++++++++++++------------ 5 files changed, 77 insertions(+), 77 deletions(-) (limited to 'plugins/ListeningTo/src/players') diff --git a/plugins/ListeningTo/src/players/generic.cpp b/plugins/ListeningTo/src/players/generic.cpp index db11f757d7..c4996d763b 100644 --- a/plugins/ListeningTo/src/players/generic.cpp +++ b/plugins/ListeningTo/src/players/generic.cpp @@ -20,15 +20,15 @@ Boston, MA 02111-1307, USA. #include "../stdafx.h" static UINT hTimer = NULL; -static HANDLE hLog = NULL; +static HANDLE hLog = nullptr; -GenericPlayer *singleton = NULL; +GenericPlayer *singleton = nullptr; void m_log(const wchar_t *function, const wchar_t *fmt, ...) { - if (hLog == NULL) { + if (hLog == nullptr) { hLog = mir_createLog(MODULE_NAME, L"ListeningTo log", L"c:\\temp\\listeningto.txt", 0); - if (hLog == NULL) + if (hLog == nullptr) return; } @@ -45,10 +45,10 @@ static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, case WM_COPYDATA: if (loaded) { COPYDATASTRUCT *pData = (PCOPYDATASTRUCT)lParam; - if (pData == NULL || pData->dwData != MIRANDA_DW_PROTECTION || pData->cbData == 0 || pData->lpData == NULL) + if (pData == nullptr || pData->dwData != MIRANDA_DW_PROTECTION || pData->cbData == 0 || pData->lpData == nullptr) return FALSE; - if (singleton != NULL) + if (singleton != nullptr) singleton->NewData((WCHAR *)pData->lpData, pData->cbData / 2); return TRUE; @@ -75,21 +75,21 @@ GenericPlayer::GenericPlayer() wc.lpszClassName = MIRANDA_WINDOWCLASS; RegisterClass(&wc); - hWnd = CreateWindow(MIRANDA_WINDOWCLASS, LPGENW("Miranda ListeningTo receiver"), 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL); + hWnd = CreateWindow(MIRANDA_WINDOWCLASS, LPGENW("Miranda ListeningTo receiver"), 0, 0, 0, 0, 0, nullptr, nullptr, hInst, nullptr); } GenericPlayer::~GenericPlayer() { if (hTimer != NULL) { - KillTimer(NULL, hTimer); + KillTimer(nullptr, hTimer); hTimer = NULL; } DestroyWindow(hWnd); - hWnd = NULL; + hWnd = nullptr; UnregisterClass(MIRANDA_WINDOWCLASS, hInst); - singleton = NULL; + singleton = nullptr; } void GenericPlayer::ProcessReceived() @@ -100,11 +100,11 @@ void GenericPlayer::ProcessReceived() // L"\\0\\0\\0\\0<Artist>\\0<Album>\\0<Track>\\0<Year>\\0<Genre>\\0<Length (secs)>\\0\\0" WCHAR *p1 = wcsstr(received, L"\\0"); - if (IsEmpty(received) || p1 == NULL) + if (IsEmpty(received) || p1 == nullptr) return; // Process string - WCHAR *parts[11] = { 0 }; + WCHAR *parts[11] = {}; int pCount = 0; WCHAR *p = received; do { @@ -113,8 +113,8 @@ void GenericPlayer::ProcessReceived() pCount++; p = p1 + 2; p1 = wcsstr(p, L"\\0"); - } while (p1 != NULL && pCount < 10); - if (p1 != NULL) + } while (p1 != nullptr && pCount < 10); + if (p1 != nullptr) *p1 = '\0'; parts[pCount] = p; @@ -157,7 +157,7 @@ void GenericPlayer::ProcessReceived() else li->ptszPlayer = mir_wstrdup(player->name); - if (parts[9] != NULL) { + if (parts[9] != nullptr) { long length = _wtoi(parts[9]); if (length > 0) { li->ptszLength = (wchar_t*)mir_alloc(10 * sizeof(wchar_t)); @@ -177,7 +177,7 @@ void GenericPlayer::ProcessReceived() // Put back the '\\'s for (int i = 1; i <= pCount; i++) *(parts[i] - 2) = L'\\'; - if (p1 != NULL) + if (p1 != nullptr) *p1 = L'\\'; wcscpy(last_received, received); @@ -189,13 +189,13 @@ void GenericPlayer::ProcessReceived() static VOID CALLBACK SendTimerProc(HWND, UINT, UINT_PTR, DWORD) { - KillTimer(NULL, hTimer); + KillTimer(nullptr, hTimer); hTimer = NULL; if (!loaded) return; - if (singleton != NULL) + if (singleton != nullptr) singleton->ProcessReceived(); } @@ -213,7 +213,7 @@ void GenericPlayer::NewData(const WCHAR *data, size_t len) received[len] = L'\0'; if (hTimer) - KillTimer(NULL, hTimer); - hTimer = SetTimer(NULL, NULL, 300, SendTimerProc); // Do the processing after we return true + KillTimer(nullptr, hTimer); + hTimer = SetTimer(nullptr, NULL, 300, SendTimerProc); // Do the processing after we return true } } diff --git a/plugins/ListeningTo/src/players/itunes.cpp b/plugins/ListeningTo/src/players/itunes.cpp index 167779db76..49def11904 100644 --- a/plugins/ListeningTo/src/players/itunes.cpp +++ b/plugins/ListeningTo/src/players/itunes.cpp @@ -31,11 +31,11 @@ ITunes::ITunes() filename[0] = L'\0'; - hwnd = NULL; - iTunesApp = NULL; - track = NULL; - file = NULL; - ret = NULL; + hwnd = nullptr; + iTunesApp = nullptr; + track = nullptr; + file = nullptr; + ret = nullptr; } void ITunes::FindWindow() @@ -51,9 +51,9 @@ void ITunes::FreeTempData() RELEASE(track); RELEASE(iTunesApp); - if (ret != NULL) { + if (ret != nullptr) { SysFreeString(ret); - ret = NULL; + ret = nullptr; } } @@ -66,10 +66,10 @@ BOOL ITunes::InitAndGetFilename() // Find window FindWindow(); - if (hwnd == NULL) + if (hwnd == nullptr) return FALSE; - CALL(CoCreateInstance(CLSID_iTunesApp, NULL, CLSCTX_LOCAL_SERVER, __uuidof(iTunesApp), (void **)&iTunesApp)); + CALL(CoCreateInstance(CLSID_iTunesApp, nullptr, CLSCTX_LOCAL_SERVER, __uuidof(iTunesApp), (void **)&iTunesApp)); ITPlayerState state; CALL(iTunesApp->get_PlayerState(&state)); @@ -77,7 +77,7 @@ BOOL ITunes::InitAndGetFilename() return FALSE; CALL(iTunesApp->get_CurrentTrack(&track)); - if (track == NULL) + if (track == nullptr) return FALSE; CALL(track->QueryInterface(__uuidof(file), (void **)&file)); @@ -132,10 +132,10 @@ BOOL ITunes::FillCache() listening_info.ptszType = mir_wstrdup(L"Music"); - if (listening_info.ptszTitle == NULL) { + if (listening_info.ptszTitle == nullptr) { // Get from filename WCHAR *p = wcsrchr(filename, '\\'); - if (p != NULL) + if (p != nullptr) p++; else p = filename; @@ -143,7 +143,7 @@ BOOL ITunes::FillCache() listening_info.ptszTitle = mir_wstrdup(p); wchar_t *pt = wcsrchr(listening_info.ptszTitle, '.'); - if (pt != NULL) + if (pt != nullptr) *p = '\0'; } diff --git a/plugins/ListeningTo/src/players/player.cpp b/plugins/ListeningTo/src/players/player.cpp index a2bfcd1751..666f640cf8 100644 --- a/plugins/ListeningTo/src/players/player.cpp +++ b/plugins/ListeningTo/src/players/player.cpp @@ -44,7 +44,7 @@ BOOL Player::GetListeningInfo(LISTENINGTOINFO *lti) if (listening_info.cbSize == 0) return false; - if (lti != NULL) + if (lti != nullptr) CopyListeningInfo(lti, &listening_info); return true; } @@ -62,7 +62,7 @@ ExternalPlayer::ExternalPlayer() name = L"ExternalPlayer"; needPoll = TRUE; - window_classes = NULL; + window_classes = nullptr; num_window_classes = 0; found_window = FALSE; } @@ -73,10 +73,10 @@ ExternalPlayer::~ExternalPlayer() HWND ExternalPlayer::FindWindow() { - HWND hwnd = NULL; + HWND hwnd = nullptr; for (int i = 0; i < num_window_classes; i++) { - hwnd = ::FindWindow(window_classes[i], NULL); - if (hwnd != NULL) + hwnd = ::FindWindow(window_classes[i], nullptr); + if (hwnd != nullptr) break; } return hwnd; @@ -84,7 +84,7 @@ HWND ExternalPlayer::FindWindow() BOOL ExternalPlayer::GetListeningInfo(LISTENINGTOINFO *lti) { - if (FindWindow() == NULL) + if (FindWindow() == nullptr) return FALSE; return Player::GetListeningInfo(lti); @@ -95,8 +95,8 @@ BOOL ExternalPlayer::GetListeningInfo(LISTENINGTOINFO *lti) CodeInjectionPlayer::CodeInjectionPlayer() { name = L"CodeInjectionPlayer"; - dll_name = NULL; - message_window_class = NULL; + dll_name = nullptr; + message_window_class = nullptr; next_request_time = 0; } @@ -113,12 +113,12 @@ void CodeInjectionPlayer::InjectCode() // Window is opened? HWND hwnd = FindWindow(); - if (hwnd == NULL) + if (hwnd == nullptr) return; // Msg Window is registered? (aka plugin is running?) - HWND msgHwnd = ::FindWindow(message_window_class, NULL); - if (msgHwnd != NULL) + HWND msgHwnd = ::FindWindow(message_window_class, nullptr); + if (msgHwnd != nullptr) return; @@ -131,7 +131,7 @@ void CodeInjectionPlayer::InjectCode() return; char *p = strrchr(dll_path, '\\'); - if (p == NULL) + if (p == nullptr) return; p++; @@ -153,21 +153,21 @@ void CodeInjectionPlayer::InjectCode() GetWindowThreadProcessId(hwnd, &pid); HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, pid); - if (hProcess == NULL) + if (hProcess == nullptr) return; - char *_dll = (char *)VirtualAllocEx(hProcess, NULL, len + 1, MEM_COMMIT, PAGE_READWRITE); - if (_dll == NULL) { + char *_dll = (char *)VirtualAllocEx(hProcess, nullptr, len + 1, MEM_COMMIT, PAGE_READWRITE); + if (_dll == nullptr) { CloseHandle(hProcess); return; } - WriteProcessMemory(hProcess, _dll, dll_path, len + 1, NULL); + WriteProcessMemory(hProcess, _dll, dll_path, len + 1, nullptr); HMODULE hKernel32 = GetModuleHandleA("kernel32"); HANDLE hLoadLibraryA = GetProcAddress(hKernel32, "LoadLibraryA"); DWORD threadId; - HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)hLoadLibraryA, _dll, 0, &threadId); - if (hThread == NULL) { + HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, (LPTHREAD_START_ROUTINE)hLoadLibraryA, _dll, 0, &threadId); + if (hThread == nullptr) { VirtualFreeEx(hProcess, _dll, len + 1, MEM_RELEASE); CloseHandle(hProcess); return; diff --git a/plugins/ListeningTo/src/players/watrack.cpp b/plugins/ListeningTo/src/players/watrack.cpp index 895c555b91..bbbd1ee81f 100644 --- a/plugins/ListeningTo/src/players/watrack.cpp +++ b/plugins/ListeningTo/src/players/watrack.cpp @@ -19,13 +19,13 @@ Boston, MA 02111-1307, USA. #include "../stdafx.h" -static WATrack *instance = NULL; +static WATrack *instance = nullptr; int NewStatusCallback(WPARAM wParam, LPARAM lParam) { if (!loaded) return 0; - if (instance != NULL) + if (instance != nullptr) instance->NewStatus(wParam, lParam); return 0; } @@ -34,16 +34,16 @@ WATrack::WATrack() { name = L"WATrack"; instance = this; - hNewStatusHook = NULL; + hNewStatusHook = nullptr; } WATrack::~WATrack() { - if (hNewStatusHook != NULL) { + if (hNewStatusHook != nullptr) { UnhookEvent(hNewStatusHook); - hNewStatusHook = NULL; + hNewStatusHook = nullptr; } - instance = NULL; + instance = nullptr; } void WATrack::EnableDisable() @@ -53,7 +53,7 @@ void WATrack::EnableDisable() return; } - if (hNewStatusHook == NULL) + if (hNewStatusHook == nullptr) hNewStatusHook = HookEvent(ME_WAT_NEWSTATUS, NewStatusCallback); } @@ -72,13 +72,13 @@ void WATrack::NewStatus(int event, int value) void WATrack::GetData() { - SONGINFO *si = NULL; + SONGINFO *si = nullptr; int playing = CallService(MS_WAT_GETMUSICINFO, WAT_INF_UNICODE, (LPARAM)&si); FreeData(); // See if something is playing - if (playing == WAT_RES_NOTFOUND || si == NULL || si->status != 1 || (IsEmpty(si->artist) && IsEmpty(si->title))) + if (playing == WAT_RES_NOTFOUND || si == nullptr || si->status != 1 || (IsEmpty(si->artist) && IsEmpty(si->title))) return; // Copy new data diff --git a/plugins/ListeningTo/src/players/wmp.cpp b/plugins/ListeningTo/src/players/wmp.cpp index a78f6f3a57..c69f288765 100644 --- a/plugins/ListeningTo/src/players/wmp.cpp +++ b/plugins/ListeningTo/src/players/wmp.cpp @@ -25,7 +25,7 @@ static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, static UINT hTimer = NULL; -WindowsMediaPlayer *singleton = NULL; +WindowsMediaPlayer *singleton = nullptr; WindowsMediaPlayer::WindowsMediaPlayer() { @@ -39,21 +39,21 @@ WindowsMediaPlayer::WindowsMediaPlayer() wc.lpszClassName = WMP_WINDOWCLASS; RegisterClass(&wc); - hWnd = CreateWindow(WMP_WINDOWCLASS, LPGENW("Miranda ListeningTo WMP receiver"), 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL); + hWnd = CreateWindow(WMP_WINDOWCLASS, LPGENW("Miranda ListeningTo WMP receiver"), 0, 0, 0, 0, 0, nullptr, nullptr, hInst, nullptr); } WindowsMediaPlayer::~WindowsMediaPlayer() { if (hTimer != NULL) { - KillTimer(NULL, hTimer); + KillTimer(nullptr, hTimer); hTimer = NULL; } DestroyWindow(hWnd); - hWnd = NULL; + hWnd = nullptr; UnregisterClass(WMP_WINDOWCLASS, hInst); - singleton = NULL; + singleton = nullptr; } void WindowsMediaPlayer::ProcessReceived() @@ -68,13 +68,13 @@ void WindowsMediaPlayer::ProcessReceived() WCHAR *p1 = wcsstr(received, L"\\0"); - if (received[0] == L'\0' || p1 == NULL) { + if (received[0] == L'\0' || p1 == nullptr) { NotifyInfoChanged(); return; } // Process string - WCHAR *parts[8] = { 0 }; + WCHAR *parts[8] = {}; int pCount = 0; WCHAR *p = received; do { @@ -83,8 +83,8 @@ void WindowsMediaPlayer::ProcessReceived() pCount++; p = p1 + 2; p1 = wcsstr(p, L"\\0"); - } while (p1 != NULL && pCount < 7); - if (p1 != NULL) + } while (p1 != nullptr && pCount < 7); + if (p1 != nullptr) *p1 = L'\0'; parts[pCount] = p; @@ -104,7 +104,7 @@ void WindowsMediaPlayer::ProcessReceived() // Put back the '\\'s for (int i = 1; i <= pCount; i++) *(parts[i] - 2) = L'\\'; - if (p1 != NULL) + if (p1 != nullptr) *p1 = L'\\'; } @@ -113,13 +113,13 @@ void WindowsMediaPlayer::ProcessReceived() static VOID CALLBACK SendTimerProc(HWND, UINT, UINT_PTR, DWORD) { - KillTimer(NULL, hTimer); + KillTimer(nullptr, hTimer); hTimer = NULL; if (!loaded) return; - if (singleton != NULL) + if (singleton != nullptr) singleton->ProcessReceived(); } @@ -133,8 +133,8 @@ void WindowsMediaPlayer::NewData(const WCHAR *data, size_t len) received[len] = '\0'; if (hTimer) - KillTimer(NULL, hTimer); - hTimer = SetTimer(NULL, NULL, 300, SendTimerProc); // Do the processing after we return true + KillTimer(nullptr, hTimer); + hTimer = SetTimer(nullptr, NULL, 300, SendTimerProc); // Do the processing after we return true } } @@ -144,14 +144,14 @@ static LRESULT CALLBACK ReceiverWndProc(HWND hWnd, UINT message, WPARAM wParam, if (!loaded) return FALSE; - if (singleton == NULL || !singleton->enabled) + if (singleton == nullptr || !singleton->enabled) return FALSE; COPYDATASTRUCT* pData = (PCOPYDATASTRUCT)lParam; - if (pData->dwData != 0x547 || pData->cbData == 0 || pData->lpData == NULL) + if (pData->dwData != 0x547 || pData->cbData == 0 || pData->lpData == nullptr) return FALSE; - if (singleton != NULL) + if (singleton != nullptr) singleton->NewData((WCHAR *)pData->lpData, pData->cbData / 2); return TRUE; -- cgit v1.2.3