我调用子程序exe,通过各位的creatprocess, winexec, shellexecute和COM调用,为什么输入参数设为Sleep, lpCmdLine == "Sleep"却不为真?呵呵,哪里错了?int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
         ...
if(lpCmdLine == "Sleep")
{
MessageBox(NULL, "Sleep", "test", MB_OK);
}
else if(lpCmdLine == "Restart")
{
MessageBox(NULL, "Restart", "test", MB_OK);
}
else if(lpCmdLine == "Suspend")
{
MessageBox(NULL, "Suspend", "test", MB_OK);
}
else
{
MessageBox( NULL, "Illegal", "test", MB_OK);
} // Main message loop:
while (GetMessage(&msg, NULL, 0, 0)) 
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}

解决方案 »

  1.   

    你输出lpCmdLine看看,它应该包括这个.exe文件和空格
      

  2.   

    //you should use getcommandline
    WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR CmdLinePointer, int WndShowState)
    {
         if(GetCmdLinePara()=="-y")
          ...
    }
    AnsiString GetCmdLinePara(void)
    {
            char *p=GetCommandLine();
            do
            {
            p++;
            }while(*p!='"');
            p++;
            if(*p=='\0')
            {
            return NULL;
            }
            else
            {
            while(*p==' ')
            {
            p++;
            }
            return (AnsiString)p;
            }
    }
      

  3.   

    你输出lpCmdLine看看,它应该包括这个.exe文件和空格
    -------------------------------------------------------------------------------------
    输出是正确的,如输入"cmd.exe Sleep", 那么LPSTR lpCmdLine为"Sleep"
      

  4.   

    还要看你是哪种方式调用的?
    Creatprocess, WinExec, ShellExecute或COM调用
      

  5.   

    strcmp(lpCmdLine,"Sleep") == 0