-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef guard_winMain_h_jh4ser564uj | ||
#define guard_winMain_h_jh4ser564uj | ||
|
||
#include <cage-engine/core.h> | ||
|
||
#ifdef _WIN32 | ||
|
||
#ifndef VC_EXTRALEAN | ||
#define VC_EXTRALEAN | ||
#endif | ||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif | ||
#include <windows.h> | ||
|
||
namespace cage | ||
{ | ||
namespace privat | ||
{ | ||
CAGE_ENGINE_API std::pair<int, const char **> winMainParams(); | ||
} | ||
} | ||
|
||
int main(int argc, const char *args[]); | ||
|
||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | ||
{ | ||
const auto cmd = ::cage::privat::winMainParams(); | ||
return ::main(cmd.first, cmd.second); | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifdef _WIN32 | ||
|
||
#include <cage-engine/core.h> | ||
|
||
#ifndef VC_EXTRALEAN | ||
#define VC_EXTRALEAN | ||
#endif | ||
#ifndef NOMINMAX | ||
#define NOMINMAX | ||
#endif | ||
#include <windows.h> | ||
|
||
namespace cage | ||
{ | ||
namespace privat | ||
{ | ||
CAGE_API_EXPORT std::pair<int, const char **> winMainParams() | ||
{ | ||
using namespace cage; | ||
|
||
CAGE_LOG(SeverityEnum::Info, "cage-engine", "winMain parsing parameters"); | ||
|
||
static int consoleDummy = []() | ||
{ | ||
AllocConsole(); // allocate new console for sub-programs | ||
ShowWindow(GetConsoleWindow(), SW_HIDE); | ||
return 0; | ||
}(); | ||
(void)consoleDummy; | ||
|
||
LPWSTR cmdLine = GetCommandLineW(); | ||
int argc; | ||
LPWSTR *argvW = CommandLineToArgvW(cmdLine, &argc); | ||
|
||
if (argvW == nullptr) | ||
{ | ||
static_assert(sizeof(DWORD) == sizeof(uint32)); | ||
CAGE_LOG_THROW(Stringizer() + "error code: " + (uint32)GetLastError()); | ||
CAGE_THROW_CRITICAL(Exception, "failed to convert command line arguments to an array (CommandLineToArgvW)"); | ||
} | ||
|
||
// convert wide char to multibyte | ||
char **argv = new char *[argc]; | ||
for (int i = 0; i < argc; i++) | ||
{ | ||
size_t len = wcslen(argvW[i]) + 1; | ||
argv[i] = new char[len]; | ||
wcstombs(argv[i], argvW[i], len); | ||
} | ||
|
||
return { argc, (const char **)argv }; | ||
} | ||
} | ||
} | ||
|
||
#endif |