CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 1999
    Posts
    22

    How can I know if ShellExecute has failed.

    The ShellExecute method is nice. It returned value is a hInst. if the file name provided is not appropriate (not existing or not openable) I need to know about that!
    Unfortunately on failure, it dos not return null.

    How can I know if ShellExecute has failed.



  2. #2
    Join Date
    Jun 1999
    Posts
    319

    Re: How can I know if ShellExecute has failed.

    You're right. ShellExecute is a great function. So because it's great...
    This is from MSDN:
    Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. 0 The operating system is out of memory or resources.
    ERROR_FILE_NOT_FOUND The specified file was not found.
    ERROR_PATH_NOT_FOUND The specified path was not found.
    ERROR_BAD_FORMAT The .exe file is invalid (non-Win32® .exe or error in .exe image).
    SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
    SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
    SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
    SE_ERR_DDEFAIL The DDE transaction failed.
    SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
    SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found.
    SE_ERR_FNF The specified file was not found.
    SE_ERR_NOASSOC There is no application associated with the given file name extension.
    SE_ERR_OOM There was not enough memory to complete the operation.
    SE_ERR_PNF The specified path was not found.
    SE_ERR_SHARE A sharing violation occurred.

    As you can see there are some error messages for your problem.
    If this doesn't help you can try with GetLastError function.

    Let meknow if it works ok for you.
    Best regards,
    Faby


  3. #3
    Join Date
    Jul 1999
    Posts
    22

    Re: How can I know if ShellExecute has failed.

    Hi,
    The return value is a HINSTANCE and not an int, so I couldn't write:
    if(instance<32..)
    neither
    if(*instance<32..)
    error in compilation.
    However, the GetLastError helped me a lot and I checked its returned value.

    If you have an answer to my first point, I'll be happier!
    Thanks a lot.
    Charly.


  4. #4
    Join Date
    Jun 1999
    Posts
    319

    Re: How can I know if ShellExecute has failed.

    You could cast the HINSTANCE to a int value. For ex.:
    if(((int)instance) <32..)

    It should work. It does?
    Regards,
    Faby


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured