Click here to Skip to main content
13,591,190 members
Rate this:
Please Sign up or sign in to vote.
See more:

How can we run a C program on clicking a button in any GUI?
Posted 15-Feb-13 17:50pm
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"?
jakr13 16-Feb-13 1:15am
Better be specific with the question,so that everyone can understand and clear your doubts.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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]

Google is your friend for these. I assume you know what to do...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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().
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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:[^][^][^]

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.180618.1 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100