Skip to content

Commit

Permalink
Use "standard" int main in Windows builds
Browse files Browse the repository at this point in the history
Using WinMain is not necessary in order to get access to the "wide" command
line, and makes the MSVCRT skip all the initialisation steps needed for
"Console API" to work correctly, leading to the program having no output in
Windows console programs that use it - most notably, cmd.exe.
  • Loading branch information
lighterowl committed Feb 5, 2020
1 parent 92246c3 commit 6d381d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tsMuxer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 3.1)
project (tsmuxer LANGUAGES CXX)

add_executable (tsmuxer WIN32
add_executable (tsmuxer
aac.cpp
aacStreamReader.cpp
AbstractDemuxer.cpp
Expand Down
16 changes: 8 additions & 8 deletions tsMuxer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,11 @@ All parameters in this group start with two dashes:\n\

#ifdef _WIN32
#include <shellapi.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
#endif

int main(int argc, char** argv)
{
int argc;
#ifdef _WIN32
auto argvWide = CommandLineToArgvW(GetCommandLineW(), &argc);
std::vector<std::string> argv_utf8;
argv_utf8.reserve(static_cast<std::size_t>(argc));
Expand All @@ -560,15 +562,13 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
argv_utf8.emplace_back(toUtf8(argvWide[i]));
}
LocalFree(argvWide);
std::vector<char*> argv;
argv.reserve(argv_utf8.size());
std::vector<char*> argv_vec;
argv_vec.reserve(argv_utf8.size());
for (auto&& s : argv_utf8)
{
argv.push_back(&s[0]);
argv_vec.push_back(&s[0]);
}
#else
int main(int argc, char** argv)
{
argv = &argv_vec[0];
#endif
LTRACE(LT_INFO, 2, "tsMuxeR version " TSMUXER_VERSION << ". github.com/justdan96/tsMuxer");
int firstMplsOffset = 0;
Expand Down

3 comments on commit 6d381d6

@lighterowl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abakum @qyot27 Should be fine now, here's the MXE32 build running in cmd.exe
Capture
:
... and the MSYS2 build :
Capture2

@abakum
Copy link
Contributor

@abakum abakum commented on 6d381d6 Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since now the tsMuxeR requires .meta in utf8, and many programs write it in 8-bit encoding, it is necessary ANNOUNCE this for save compatibility!

@abakum
Copy link
Contributor

@abakum abakum commented on 6d381d6 Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.