Skip to content

Instantly share code, notes, and snippets.

@drewsberry
Last active September 9, 2015 16:06
Show Gist options
  • Save drewsberry/fe3b0d11618d3a57b0a5 to your computer and use it in GitHub Desktop.
Save drewsberry/fe3b0d11618d3a57b0a5 to your computer and use it in GitHub Desktop.
Get argv equivalent in WinMain()
#include <windows.h>
#include <atlstr.h>
#include <cstdlib>
#define NOTUSED(var) (void)(var)
#define FLAG_STR "--help"
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPST lpCmdLine,
_In_ int nCmdShow
)
{
NOTUSED(hInstance);
NOTUSED(hPrevInstance);
NOTUSED(lpCmdLine);
NOTUSED(nCmdShow);
LPWSTR *argList;
int argCount;
argList = CommandLineToArgW(GetCommandLine(), &argCount);
std::string argListStr[argCount];
for (int i = 0; i < argCount; i++)
{
std::stream argStr = CW2A(argList[i]);
if (!argStr.compare(FLAG_STR))
{
exit(10);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment