Creating a Program Shortcut

okay, so now that I have written the code that I need for my school project, I would like to create a shortcut on my home screen for the program. I was able to create a shortcut for the .exe, but when I run it and press enter, it automatically closes before outputting any results.
Does the same thing happen when you execute the exe directly? It sounds like you're not holding the console window open before returning from main.
no, it runs fine when I use it in the compiler, it just closes when I use it as a shortcut.
So will using system() allow the program to run as a shortcut?
no, it runs fine when I use it in the compiler, it just closes when I use it as a shortcut.

By compiler I take it you mean IDE? It's the IDE which waits for you to click on a key, before it allows the application's console window to close.

When you run the application outside of the IDE, there's nothing to stop the console window from closing unless you add code to get your application to wait for the user itself (as shown in the post which Duoas provided the link to.)

So will using system() allow the program to run as a shortcut?

This question does not really make sense...

I assume here that you're talking about Windows?

You can't run a program as a shortcut in any way. But you can launch an app using (or via) a shortcut.

When you create a shortcut for an app you create a .lnk file which contains the path to the executable file you want to launch, plus assorted settings inc. where to find an icon.

When you double-click on the shortcut, or right-click and Run, it's Explorer.exe that opens the .lnk file, reads the app's path and settings out of it, and then launches the app for you.

If you want to use system() with a shortcut then you have to do the work instead of Explorer. That is, you first have to read the path and setting stored in the shortcut, using IShellLink, and then call system() (which calls CreateProcess) passing it the path you extracted. Or call CreateProces directly.

Whether you start the program via a shortcut or by launching the exe directly from Explorer, it still won't wait for you to click on a key unless you add the necessary code.

(You can also create a shortcut for a document, if Windows recognizes the file extension e.g. .doc is associated with Microsoft Word, .bat with cmd.exe, ... In this case Explorer opens the shortcut, reads the file path, sees e.g. it's a Word document (.doc) and then launches Word passing it the path to the .doc file.)

Andy

For info about shell links, inc. example code showing how to read them.

Shell Links
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891%28v=vs.85%29.aspx
Last edited on
Topic archived. No new replies allowed.