Search code examples
visual-studiowinapimfcshellexecute

Problem launching external executable from Win32 application


I am trying to launch an external application from within my Win32 application but it's failing. Following is the code I am using:

HINSTANCE instance = ShellExecute(NULL, _T("open"), _T("loader.exe"), NULL, NULL, SW_SHOWNORMAL);
if((int)instance <= 32)
{
    _cprintf("Error = 0x%X\n", GetLastError());
    return 0;
}

The instance value I get is 0x00000002 and GetLastError returns 0x2. The same code works when I try to launch other applications like iTunes.exe or cmd.exe. Does it has anything to do with external application? By the way, win32 application and loader.exe application are located in the same folder.

Any help would be highly appreciated. Farooq-


Solution

  • Put loader.exe somewhere in the search path, or provide the full path. That is how to avoid this file not found error. Windows error codes are all documented on MSDN.