Thread: Syntax help with ShellExecute()

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    11

    Syntax help with ShellExecute()

    I'm trying to open up a specific file with ShellExecute() in my C code. How do I syntactically phrase this function? ~OR~ Could you please point me somewhere that does teach how to use the ShellExecute() function?

    Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Windows function = search Microsoft, right?

    ShellExecute - MSDN Search

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by K.Flynn View Post
    I'm trying to open up a specific file with ShellExecute() in my C code. How do I syntactically phrase this function? ~OR~ Could you please point me somewhere that does teach how to use the ShellExecute() function?

    Thanks!
    Code:
    #include <windows>
    #include <shlwapi.h>
    
    BOOL LaunchFile(char *FName)
      { PathQuoteSpaces(FName);
         return  ShellExecute(NULL,"Open",FName,NULL,NULL,SW_SHOWNORMAL) > 32; }
    Last edited by CommonTater; 06-21-2011 at 12:05 PM.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    So the only thing here that I would change would be the "FName"?

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    FName is a string variable you hand to the function... so you could call the function like this...
    Code:
    if (! LaunchFile("Myfile.pdf"))
     puts ("Error opening the file");
    Last edited by CommonTater; 06-21-2011 at 03:13 PM. Reason: missing bracket

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You just provide the name of the file that you want to deal with (the name you pass the function):
    Code:
    mybool = LaunchFile( "myfilename.foo" );
    edit - what he said


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    I get an error message saying "Cannot open include file: 'windows': No such file or directory".

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by K.Flynn View Post
    I get an error message saying "Cannot open include file: 'windows': No such file or directory".
    Try #include <windows.h>

    You should have been able to figure that out on your own...

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It's <windows.h>.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I think C++ uses headers without extensions like that a lot of the time now.
    Quote Originally Posted by CommonTater View Post
    You should have been able to figure that out on your own...
    This guy doesn't strike me as the "figure it out on my own" type.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    I think C++ uses headers without extensions like that a lot of the time now.
    That's likely why I got that wrong... been working on learning C++ lately.


    This guy doesn't strike me as the "figure it out on my own" type.
    Yup.

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    11
    Capitol! Oh yes, I have to admit, that was pretty obvious!

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by K.Flynn View Post
    Capitol! Oh yes, I have to admit, that was pretty obvious!
    Ok.. so in future when you encounter errors, make some effort to resolve them on your own.
    Troubleshooting is an essential programming skill.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. anyone knows how to use the ShellExecute command?
    By Amy N. in forum C Programming
    Replies: 6
    Last Post: 08-01-2009, 06:22 PM
  2. Shellexecute help
    By MaGaIn in forum C++ Programming
    Replies: 13
    Last Post: 11-05-2007, 07:17 PM
  3. ShellExecute Problem
    By dhrodrigues in forum Windows Programming
    Replies: 2
    Last Post: 04-12-2004, 03:17 PM
  4. ShellExecute Help!!
    By Shaman in forum C++ Programming
    Replies: 2
    Last Post: 09-22-2001, 05:40 AM

Tags for this Thread