Farooq Zaman
Farooq Zaman

Reputation: 505

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-

Upvotes: 1

Views: 714

Answers (3)

David Heffernan
David Heffernan

Reputation: 613013

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.

Upvotes: 0

JohnD
JohnD

Reputation: 14757

Error 2 is "File not found":

http://msdn.microsoft.com/en-us/library/ms681382(v=vs.85).aspx

I'm guessing it can't find loader.exe.

Upvotes: 1

Justin
Justin

Reputation: 86749

Well, error 0x2 is ERROR_FILE_NOT_FOUND

Looks like it can't find "loader.exe"

Upvotes: 2

Related Questions