Question

I'm encountering a problem when trying to pass a parameter through my program via the command line (eg. -w 1280 -h 1024) while attempting to utilize WinMain. I've looked through every topic I could find, and have created code that builds and runs, but the parameters are ignored completely!

My Code:

LPWSTR *szArgList;
int argCount;

szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount);

for(int i = 1;i < argCount;i++)
{
    if(i + 1 != argCount)
    {
        if(szArgList[i] == L"-w")
        {
            width = _wtoi(szArgList[i+1]);
        }
        else if(szArgList[i] == L"-h")
        {
            height = _wtoi(szArgList[i+1]);
        }
    }
}
MSG msg;
BOOL done=FALSE;
if(MessageBox(NULL,"Fullscreen?", "my window", MB_YESNO|MB_ICONQUESTION)==IDNO)
{
    fullscreen=FALSE;
}
if(!CreateGLWindow("Window",width,height,16,fullscreen))
{
    return 0;
}

I'm attempting to pass it as "window.exe -w 800 -h 600" (without quotes, of course) Anything i'm missing within my sleep-depraved code?

Was it helpful?

Solution

szArgList[i] == L"-w"
szArgList[i] == L"-h"

C and C++ will compare by pointer instead of character. use strcmp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top