| 83 | } |
| 84 | |
| 85 | int Main(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPWSTR /*lpstrCmdLine*/, int cmdShow) |
| 86 | { |
| 87 | Win32::SetPrivilege(SE_DEBUG_NAME, true); |
| 88 | Win32::SetPrivilege(SE_CREATE_GLOBAL_NAME, true); |
| 89 | |
| 90 | Win32::ComInitialization com(Win32::ComInitialization::ApartmentThreaded); |
| 91 | |
| 92 | // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used |
| 93 | ::DefWindowProc(nullptr, 0, 0, 0L); |
| 94 | |
| 95 | AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls |
| 96 | |
| 97 | #ifdef CONSOLE_DEBUG |
| 98 | FILE* standardOut; |
| 99 | AllocConsole(); |
| 100 | freopen_s(&standardOut, "CONOUT$", "wb", stdout); |
| 101 | auto fileGuard = make_guard([standardOut] { fclose(standardOut); }); |
| 102 | std::cout.clear(); |
| 103 | #endif |
| 104 | |
| 105 | CAppModuleInitialization moduleInit(_Module, hInstance); |
| 106 | |
| 107 | HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); |
| 108 | HANDLE hFile = nullptr, hPipe = nullptr; |
| 109 | switch (GetFileType(hStdIn)) |
| 110 | { |
| 111 | case FILE_TYPE_DISK: hFile = hStdIn; break; |
| 112 | case FILE_TYPE_PIPE: hPipe = hStdIn; break; |
| 113 | } |
| 114 | |
| 115 | if (hPipe && IsDBWinViewerActive()) |
| 116 | return ForwardMessagesFromPipe(hPipe); |
| 117 | |
| 118 | CMainFrame wndMain; |
| 119 | MessageLoop theLoop(_Module); |
| 120 | |
| 121 | auto args = Win32::GetCommandLineArguments(); |
| 122 | std::wstring fileName; |
| 123 | |
| 124 | for (size_t i = 1; i < args.size(); ++i) |
| 125 | { |
| 126 | if (boost::iequals(args[i], L"/min")) |
| 127 | { |
| 128 | cmdShow = SW_MINIMIZE; |
| 129 | } |
| 130 | else if (boost::iequals(args[i], L"/log")) |
| 131 | { |
| 132 | //wndMain.SetLogging(); // todo: implement: this feature is not usuable now. |
| 133 | } |
| 134 | else if (args[i][0] != '/') |
| 135 | { |
| 136 | if (!fileName.empty()) |
| 137 | throw std::runtime_error("multiple filenames specified on commandline"); |
| 138 | fileName = args[i]; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (wndMain.CreateEx() == nullptr) |
no test coverage detected