From 5a05bd56a05d94ac800883c92b7f75fe26c42d24 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 11 Apr 2025 00:06:47 +0800 Subject: [PATCH 01/10] $files expand from doublequote to singlequote --- singleinstance/singleinstance.cpp | 21 ++++++++++++++------- singleinstance/singleinstance.vcxproj | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/singleinstance/singleinstance.cpp b/singleinstance/singleinstance.cpp index 1c40a39..643a29c 100644 --- a/singleinstance/singleinstance.cpp +++ b/singleinstance/singleinstance.cpp @@ -18,6 +18,7 @@ Windows Registry Editor Version 5.00 */ #include +#include #include #include @@ -158,13 +159,19 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { return TRUE; } -void ArgvQuote(const std::wstring& Argument, std::wstring& CommandLine, bool Force){ +void ArgvQuote(const std::wstring& Argument, std::wstring& CommandLine, bool Force, bool singlequote){ + wchar_t mark; + if (singlequote) { + mark = L'\''; + } else { + mark = L'"'; + } if (Force == false && Argument.empty() == false && Argument.find_first_of(L" \t\n\v\"") == Argument.npos) { CommandLine.append(Argument); } else { - CommandLine.push_back(L'"'); + CommandLine.push_back(mark); for (auto It = Argument.begin();; ++It) { unsigned NumberBackslashes = 0; @@ -196,7 +203,7 @@ void ArgvQuote(const std::wstring& Argument, std::wstring& CommandLine, bool For } } - CommandLine.push_back(L'"'); + CommandLine.push_back(mark); } CommandLine.push_back(L' '); } @@ -207,16 +214,16 @@ void LaunchApp() { for (int i = 3; i < argCount; i++) { if (!lstrcmp(szArgList[i], _T("$files"))) { for (const auto& file : files) { - ArgvQuote(file, cmdLine, true); + ArgvQuote(file, cmdLine, true, true); } } else if (!lstrcmp(szArgList[i], _T("--si-timeout"))) { i++; // skip } else { - ArgvQuote(szArgList[i], cmdLine, true); + ArgvQuote(szArgList[i], cmdLine, true, false); } } - //MessageBox(0, cmdLine.c_str(), szArgList[2], 0); + // MessageBox(0, cmdLine.c_str(), szArgList[2], 0); HINSTANCE hinst = ShellExecute(0, _T("open"), szArgList[2], cmdLine.c_str(), 0, SW_SHOWNORMAL); if (reinterpret_cast(hinst) <= 32) { TCHAR buffer[256]; @@ -255,4 +262,4 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, message, wParam, lParam); } return 0; -} \ No newline at end of file +} diff --git a/singleinstance/singleinstance.vcxproj b/singleinstance/singleinstance.vcxproj index c93aebd..e04da06 100644 --- a/singleinstance/singleinstance.vcxproj +++ b/singleinstance/singleinstance.vcxproj @@ -19,7 +19,7 @@ Application true - v120 + v143 Unicode From 947ffb494e39d3bf68cdcb18698ea8137b59ef9f Mon Sep 17 00:00:00 2001 From: mrair <45960823+owenstake@users.noreply.github.com> Date: Sat, 12 Apr 2025 16:17:41 +0800 Subject: [PATCH 02/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7518c82..ffc5c53 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # context-menu-launcher Select multiple files from Windows Explorer menu and launch just one instance of process -[Download executable](https://github.com/zenden2k/context-menu-launcher/releases/tag/1.0) +[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/v1.0.1/singleinstance.exe) ## How to pass multiple files to shell context menu command (Windows Explorer) From b82436263c05a78cb8058923c67290e8ff63b1d0 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 12 Apr 2025 23:30:13 +0800 Subject: [PATCH 03/10] refine --- singleinstance/singleinstance.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/singleinstance/singleinstance.cpp b/singleinstance/singleinstance.cpp index 643a29c..522a6b8 100644 --- a/singleinstance/singleinstance.cpp +++ b/singleinstance/singleinstance.cpp @@ -21,6 +21,7 @@ Windows Registry Editor Version 5.00 #include #include #include +#include class CLimitSingleInstance { protected: @@ -212,18 +213,22 @@ void LaunchApp() { std::wstring cmdLine; for (int i = 3; i < argCount; i++) { - if (!lstrcmp(szArgList[i], _T("$files"))) { + std::wstring argStr = szArgList[i]; + std::size_t found = argStr.find(L"$files"); + if (found!=std::string::npos) { + std::wstring tmpstr; for (const auto& file : files) { - ArgvQuote(file, cmdLine, true, true); + ArgvQuote(file, tmpstr, true, true); } - } else if (!lstrcmp(szArgList[i], _T("--si-timeout"))) { + argStr = std::regex_replace(argStr, std::wregex(L"\\$files"), tmpstr); + cmdLine.append(argStr); + } else if (argStr == L"--si-timeout") { i++; // skip - } - else { - ArgvQuote(szArgList[i], cmdLine, true, false); + } else { + ArgvQuote(argStr, cmdLine, true, false); } } - // MessageBox(0, cmdLine.c_str(), szArgList[2], 0); + MessageBox(0, cmdLine.c_str(), szArgList[2], 0); HINSTANCE hinst = ShellExecute(0, _T("open"), szArgList[2], cmdLine.c_str(), 0, SW_SHOWNORMAL); if (reinterpret_cast(hinst) <= 32) { TCHAR buffer[256]; From 97078464635a6f157303770abf409b87248f8b8c Mon Sep 17 00:00:00 2001 From: mrair <45960823+owenstake@users.noreply.github.com> Date: Sat, 12 Apr 2025 23:32:45 +0800 Subject: [PATCH 04/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffc5c53..e80cb8e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # context-menu-launcher Select multiple files from Windows Explorer menu and launch just one instance of process -[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/v1.0.1/singleinstance.exe) +[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/v1.0.2/singleinstance.exe) ## How to pass multiple files to shell context menu command (Windows Explorer) From bcb92d452600d3054a19167fb3afe55ae6dbec8e Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 14 Apr 2025 21:29:17 +0800 Subject: [PATCH 05/10] refine --- singleinstance/singleinstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singleinstance/singleinstance.cpp b/singleinstance/singleinstance.cpp index 522a6b8..d90ef67 100644 --- a/singleinstance/singleinstance.cpp +++ b/singleinstance/singleinstance.cpp @@ -228,7 +228,7 @@ void LaunchApp() { ArgvQuote(argStr, cmdLine, true, false); } } - MessageBox(0, cmdLine.c_str(), szArgList[2], 0); + // MessageBox(0, cmdLine.c_str(), szArgList[2], 0); HINSTANCE hinst = ShellExecute(0, _T("open"), szArgList[2], cmdLine.c_str(), 0, SW_SHOWNORMAL); if (reinterpret_cast(hinst) <= 32) { TCHAR buffer[256]; From 9b829446f4674396003adcc3fc4bf3126b047174 Mon Sep 17 00:00:00 2001 From: mrair <45960823+owenstake@users.noreply.github.com> Date: Mon, 14 Apr 2025 21:31:33 +0800 Subject: [PATCH 06/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e80cb8e..f48a133 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # context-menu-launcher Select multiple files from Windows Explorer menu and launch just one instance of process -[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/v1.0.2/singleinstance.exe) +[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/v1.0.3/singleinstance.exe) ## How to pass multiple files to shell context menu command (Windows Explorer) From 5d7f2ee766404e8d4e1b32817443d2ec314a1166 Mon Sep 17 00:00:00 2001 From: mrair <45960823+owenstake@users.noreply.github.com> Date: Mon, 14 Apr 2025 21:34:00 +0800 Subject: [PATCH 07/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f48a133..3650928 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # context-menu-launcher Select multiple files from Windows Explorer menu and launch just one instance of process -[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/v1.0.3/singleinstance.exe) +[Download executable](https://github.com/owenstake/context-menu-launcher/releases/download/latest/singleinstance.exe) ## How to pass multiple files to shell context menu command (Windows Explorer) From 5e72591b17925ebde77e4a9e6bea4affe921d06e Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 3 May 2025 13:40:34 +0800 Subject: [PATCH 08/10] Static compilation --- README.md | 6 +++++ singleinstance/singleinstance.cpp | 36 +++++++++++++-------------- singleinstance/singleinstance.vcxproj | 3 ++- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 3650928..b7db965 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ + +# Static compilation +```powershell +& 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe' /m:8 /property:Configuration=Release .\singleinstance.sln +``` + # context-menu-launcher Select multiple files from Windows Explorer menu and launch just one instance of process diff --git a/singleinstance/singleinstance.cpp b/singleinstance/singleinstance.cpp index d90ef67..9d01a03 100644 --- a/singleinstance/singleinstance.cpp +++ b/singleinstance/singleinstance.cpp @@ -24,28 +24,28 @@ Windows Registry Editor Version 5.00 #include class CLimitSingleInstance { -protected: - DWORD m_dwLastError; - HANDLE m_hMutex; + protected: + DWORD m_dwLastError; + HANDLE m_hMutex; -public: - CLimitSingleInstance(TCHAR *strMutexName) - { - m_hMutex = CreateMutex(NULL, FALSE, strMutexName); //do early - m_dwLastError = GetLastError(); //save for use later... - } - - ~CLimitSingleInstance(){ - if (m_hMutex) //Do not forget to close handles. + public: + CLimitSingleInstance(TCHAR *strMutexName) { - CloseHandle(m_hMutex); //Do as late as possible. - m_hMutex = NULL; //Good habit to be in. + m_hMutex = CreateMutex(NULL, FALSE, strMutexName); //do early + m_dwLastError = GetLastError(); //save for use later... } - } - BOOL IsAnotherInstanceRunning(){ - return (ERROR_ALREADY_EXISTS == m_dwLastError); - } + ~CLimitSingleInstance(){ + if (m_hMutex) //Do not forget to close handles. + { + CloseHandle(m_hMutex); //Do as late as possible. + m_hMutex = NULL; //Good habit to be in. + } + } + + BOOL IsAnotherInstanceRunning(){ + return (ERROR_ALREADY_EXISTS == m_dwLastError); + } }; int timeout = 400; // ms diff --git a/singleinstance/singleinstance.vcxproj b/singleinstance/singleinstance.vcxproj index e04da06..6b3a7f2 100644 --- a/singleinstance/singleinstance.vcxproj +++ b/singleinstance/singleinstance.vcxproj @@ -14,6 +14,7 @@ {95C5CED1-7955-43FC-9EA3-E20D2CE1DEB1} Win32Proj singleinstance + 10.0 @@ -25,7 +26,7 @@ Application false - v120_xp + v143 true Unicode From fa97fbfb2c84ed42cfd200ed4651fbc6a8dac934 Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 3 May 2025 23:53:39 +0800 Subject: [PATCH 09/10] Fix 400 file run fail by set timer --- singleinstance/singleinstance.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/singleinstance/singleinstance.cpp b/singleinstance/singleinstance.cpp index 9d01a03..97a494e 100644 --- a/singleinstance/singleinstance.cpp +++ b/singleinstance/singleinstance.cpp @@ -249,6 +249,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) SetTimer(hWnd, TIMER_ID, timeout, 0); break; case WM_COPYDATA: + SetTimer(hWnd, TIMER_ID, timeout, 0); pcds = reinterpret_cast(lParam); if (pcds->dwData == 1) { LPCTSTR lpszString = reinterpret_cast(pcds->lpData); From 81029917d7e846758f80cc694285322570327745 Mon Sep 17 00:00:00 2001 From: mrair <45960823+owenstake@users.noreply.github.com> Date: Sun, 4 May 2025 01:01:39 +0800 Subject: [PATCH 10/10] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b7db965..3c7559d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # Static compilation ```powershell +# compile release & 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe' /m:8 /property:Configuration=Release .\singleinstance.sln + +# check dll depends +&'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\dumpbin.exe' /dependents .\Release\singleinstance.exe ``` # context-menu-launcher