forked from Public-Mirror/Textractor
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";
|
auto file = std::ofstream(REPLACE_SAVE_FILE, std::ios::binary) << "\xff\xfe";
|
||||||
for (auto ch : std::wstring_view(REGEX_REPLACER_INSTRUCTIONS))
|
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));
|
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;
|
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";
|
auto file = std::ofstream(REPLACE_SAVE_FILE, std::ios::binary) << "\xff\xfe";
|
||||||
for (auto ch : std::wstring_view(REPLACER_INSTRUCTIONS))
|
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));
|
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;
|
break;
|
||||||
|
@ -76,6 +76,18 @@ private:
|
|||||||
M m;
|
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
|
static struct // should be inline but MSVC (linker) is bugged
|
||||||
{
|
{
|
||||||
inline static BYTE DUMMY[100];
|
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); }
|
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>
|
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();
|
void Localize();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user