Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

How can we run a C program on clicking a button in any GUI?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Feb-13 0:59am    
Not clear. If you want to run a program, who cares how it was written, in what language?
Perhaps you don't even have and idea of compilation, linking, loading and running. And what is "any GUI"?
—SA
jakr13 16-Feb-13 1:15am    
Better be specific with the question,so that everyone can understand and clear your doubts.

In the click handler for the control, add something that starts the C program. How to do this is platform specific, and you didn't specify which platform you are interested in. For Windows, there are several ways of activating something:

WinExec() [don't use this any more]
CreateProcess() [and related]
ShellExecute()
ShellExecuteEx()

Google is your friend for these. I assume you know what to do...
 
Share this answer
 
1. Are you thinking of running C-code (automatic compile and link) or are you talking about compiled application ?

I asssume you mean writing Code in C that displays a GUI with a button ?

a. Are you searching for a way of programming a button independent from Operation System ?
You should use a library such as wxwindows, opengl or something like that.

b. You can call system() from stdlib.h independent from OS.
Depending on the Operation System you have to call different System-Calls.
For Unix you can call fork()/exec() for Windows you can use CreateProcess().
 
Share this answer
 
v3
In addition to the Windows specific calls that were provided in Solution 1, Microsoft does implement some POSIX calls that perform application launching (exec, spawn, system).

See here:
http://msdn.microsoft.com/en-us/library/431x4c1w(v=vs.110).aspx[^]
http://msdn.microsoft.com/en-us/library/20y988d2.aspx[^]
http://msdn.microsoft.com/en-us/library/277bwbdz.aspx[^]

Do note that these calls are not C/C++ native, they are OS specific as stated in the other solution. This means that they may act slightly different in different platforms and will likely be defined in different headers in each OS.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900