We only need a standard `main()` function, but using wWinMain prevents a window/task bar entry from temporarily appearing
| 21 | // We only need a standard `main()` function, but using wWinMain prevents |
| 22 | // a window/task bar entry from temporarily appearing |
| 23 | int WINAPI wWinMain( |
| 24 | HINSTANCE hInstance, |
| 25 | HINSTANCE hPrevInstance, |
| 26 | PWSTR pCmdLine, |
| 27 | int nCmdShow) { |
| 28 | int argc = 0; |
| 29 | auto argv = CommandLineToArgvW(pCmdLine, &argc); |
| 30 | |
| 31 | int repeat = 1; |
| 32 | |
| 33 | wchar_t* wpgmptr {nullptr}; |
| 34 | _get_wpgmptr(&wpgmptr); |
| 35 | // argv[0] is sometimes the first arg, sometimes the program name |
| 36 | if ( |
| 37 | std::filesystem::weakly_canonical(argv[0]) |
| 38 | != std::filesystem::weakly_canonical(wpgmptr)) { |
| 39 | try { |
| 40 | repeat = std::stoi(argv[0]); |
| 41 | } catch (...) { |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if (repeat == 1) { |
| 46 | const APIEvent ge { |
| 47 | APIEvent::EVT_REMOTE_USER_ACTION, |
| 48 | STRINGIFY(REMOTE_ACTION), |
| 49 | }; |
| 50 | ge.Send(); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | auto payload = nlohmann::json::array(); |
| 55 | for (int i = 0; i < repeat; ++i) { |
| 56 | payload.push_back(nlohmann::json::array( |
| 57 | {APIEvent::EVT_REMOTE_USER_ACTION, STRINGIFY(REMOTE_ACTION)})); |
| 58 | } |
| 59 | const APIEvent me { |
| 60 | APIEvent::EVT_MULTI_EVENT, |
| 61 | payload.dump(), |
| 62 | }; |
| 63 | me.Send(); |
| 64 | return 0; |
| 65 | } |