Don't use TerminateProcess() to end programs... it is a last-resort, hatchet-job way of killing the unruly.
I don't know why you are opening it as a DDE process, but in either case, you should refrain from using numbers directly in your code. The <windows.h> header includes everything you need to write something that can be read.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
BOOL ShowUserStats( LPCSTR filename )
{
BOOL result;
SHELLEXECUTEINFO exInfo;
exInfo.cbSize = sizeof( SHELLEXECUTEINFO );
exInfo.fMask = SEE_MASK_FLAG_NO_UI
| SEE_MASK_NOCLOSEPROCESS;
exInfo.hwnd = NULL;
exInfo.lpVerb = "open";
exInfo.lpFile = filename;
exInfo.lpParameters = NULL;
exInfo.lpDirectory = NULL;
result = ShellExecuteEx( &exInfo );
if (!result)
{
MessageBox( NULL, "fooey", "caption", MB_OK );
}
return result;
}
|
Be sure to pay attention to the documentation for these commands.
The SEE_MASK_FLAG_NO_UI flag keeps Windows from displaying its own error dialogue if something goes wrong (since you want to display your own instead).
The SEE_MASK_NOCLOSEPROCESS means to do a non-blocking ShellExecute(). That is to say that the 'filename' document is opened (or fails to open) and control is immediately returned to your program. The handle of the new process is listed in exInfo.hProcess. If the document failed to open, hProcess lists the reason why:
SE_ERR_FNF File not found
SE_ERR_PNF Path not found
SE_ERR_ACCESSDENIED Access denied
SE_ERR_OOM Out of memory
SE_ERR_DLLNOTFOUND Dynamic-link library not found
SE_ERR_SHARE Cannot share open file
SE_ERR_ASSOCINCOMPLETE File association information not complete
SE_ERR_DDETIMEOUT DDE operation timed out
SE_ERR_DDEFAIL DDE operation failed
SE_ERR_DDEBUSY DDE operation busy
SE_ERR_NOASSOC File association not available
The first argument to MessageBox() should be the handle to your application's active window.
The third argument is the caption of the dialogue box, and should be the same as your application's caption.
Hope this helps.
[edit] Oh yeah, notice how you only need to check the success or failure result to determine if something went wrong.