mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 00:44:13 +08:00
fix crash on windows 11
This commit is contained in:
parent
fdc8a13b36
commit
823987e79f
@ -49,7 +49,7 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
|
||||
auto file = std::ofstream(REPLACE_SAVE_FILE, std::ios::binary) << "\xff\xfe";
|
||||
for (auto ch : std::wstring_view(REGEX_REPLACER_INSTRUCTIONS))
|
||||
file << (ch == L'\n' ? std::string_view("\r\0\n", 4) : std::string_view((char*)&ch, 2));
|
||||
_spawnlp(_P_DETACH, "notepad", "notepad", REPLACE_SAVE_FILE, NULL); // show file to user
|
||||
SpawnThread([] { _spawnlp(_P_DETACH, "notepad", "notepad", REPLACE_SAVE_FILE, NULL); }); // show file to user
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -105,7 +105,7 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
|
||||
auto file = std::ofstream(REPLACE_SAVE_FILE, std::ios::binary) << "\xff\xfe";
|
||||
for (auto ch : std::wstring_view(REPLACER_INSTRUCTIONS))
|
||||
file << (ch == L'\n' ? std::string_view("\r\0\n", 4) : std::string_view((char*)&ch, 2));
|
||||
_spawnlp(_P_DETACH, "notepad", "notepad", REPLACE_SAVE_FILE, NULL); // show file to user
|
||||
SpawnThread([] { _spawnlp(_P_DETACH, "notepad", "notepad", REPLACE_SAVE_FILE, NULL); }); // show file to user
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -76,6 +76,18 @@ private:
|
||||
M m;
|
||||
};
|
||||
|
||||
template <typename F>
|
||||
void SpawnThread(const F& f) // works in DllMain unlike std thread
|
||||
{
|
||||
F* copy = new F(f);
|
||||
CloseHandle(CreateThread(nullptr, 0, [](void* copy)
|
||||
{
|
||||
(*(F*)copy)();
|
||||
delete (F*)copy;
|
||||
return 0UL;
|
||||
}, copy, 0, nullptr));
|
||||
}
|
||||
|
||||
static struct // should be inline but MSVC (linker) is bugged
|
||||
{
|
||||
inline static BYTE DUMMY[100];
|
||||
@ -134,7 +146,7 @@ template <typename... Args>
|
||||
inline void TEXTRACTOR_MESSAGE(const wchar_t* format, const Args&... args) { MessageBoxW(NULL, FormatString(format, args...).c_str(), L"Textractor", MB_OK); }
|
||||
|
||||
template <typename... Args>
|
||||
inline void TEXTRACTOR_DEBUG(const wchar_t* format, const Args&... args) { std::thread([=] { TEXTRACTOR_MESSAGE(format, args...); }).detach(); }
|
||||
inline void TEXTRACTOR_DEBUG(const wchar_t* format, const Args&... args) { SpawnThread([=] { TEXTRACTOR_MESSAGE(format, args...); }); }
|
||||
|
||||
void Localize();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user