From: porkchop@invalid.foo   
      
   On Wed, 31 Dec 2025 09:37:08 -0000 (UTC), Lawrence D’Oliveiro wrote:   
      
   > Are there any standards for how C argc/argv are supposed to behave on   
   > Windows?   
      
   Good question, some more ways to open things (that I know of),   
   see 2nd example for 'sort of' argc/argv...   
      
   #define WIN32_LEAN_AND_MEAN   
   #include    
   #include    
      
   int open_app(const wchar_t *exe_or_path) {   
    HINSTANCE r = ShellExecuteW(NULL, L"open", exe_or_path, NULL, NULL,   
   SW_SHOWNORMAL);   
    return ((INT_PTR)r > 32) ? 0 : -1;   
   }   
      
   open_app(L"notepad.exe");   
   open_app(L"C:\\Windows\\System32\\calc.exe");   
      
   or...   
      
   #define WIN32_LEAN_AND_MEAN   
   #include    
   #include    
      
   int launch_app(const wchar_t *cmdline) {   
    STARTUPINFOW si;   
    PROCESS_INFORMATION pi;   
      
    ZeroMemory(&si, sizeof si);   
    ZeroMemory(&pi, sizeof pi);   
    si.cb = sizeof si;   
      
    /* CreateProcess *may modify the buffer */   
    wchar_t buf[1024];   
    wcsncpy(buf, cmdline, 1023);   
    buf[1023] = L'\0';   
      
    if (!CreateProcessW(   
    NULL, // application name (NULL = parse from cmdline)   
    buf, // command line (MUTABLE) <--   
    NULL, NULL, // process/thread security   
    FALSE, // inherit handles   
    0, // creation flags   
    NULL, // environment   
    NULL, // working directory   
    &si,   
    &pi))   
    return -1;   
      
    /* fire-and-forget */   
    CloseHandle(pi.hThread);   
    CloseHandle(pi.hProcess);   
    return 0;   
   }   
      
   launch_app(L"notepad.exe C:\\temp\\notes.txt");   
   launch_app(L\"\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" --fullscreen   
   video.mp4\");   
      
   --   
   :wq   
   Mike Sanders   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|