Thread: WinAPI > C -- Executing a program

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    5

    WinAPI > C -- Executing a program

    Good evening, So i've this project to create a window where i can execute programs from. I'm really tired of searching so i decided to ask for someone's help. anyways i made a program that shows a window etc but my problem is that i want to execute some functions, such as printf("hello world!").. I dont' know how to bring that .exe file and i don't know how to put it, i've a feeling that i've to use createProcess but i don't know how to put it. To be more specific: i wanna execute this simple program on my window:
    int n;printf("Enter an integer");scanf("%d",n);
    for example, that's what i want. Hope that you get what i mean. Program used: Code::Blocks Language: C, not c++. Thanks.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    There's this WinAPI function called CreateProcess that you can use.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    5
    Yes i know GReaper but i don't know how to use it can you give me an example? with creating a process and a simple program like a : printf() and scanf()?
    Would be really appreciated.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,656
    > To be more specific: i wanna execute this simple program on my window:
    > int n;printf("Enter an integer");scanf("%d",n);
    Are you talking about writing an IDE, where
    - you can type in things like int n;printf("Enter an integer");scanf("%d",n);
    - press some button on your program called 'compile', which takes whatever is written and compiles it.
    - press some other button on your program called 'run' which runs the executable, with stdio redirected to your window.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    You should read its documentation, it isn't that long. It explains in detail how to use it.

    If you want examples, here are some at stack overflow.
    Devoted my life to programming...

  6. #6
    Registered User
    Join Date
    Dec 2018
    Posts
    5
    something like the last thing you said: Like pressing a button that runs a specified function.
    Okay i've attached a picture :
    You see in files>TP N1>Exercice 1:
    when i click on exercice one i want to get an executed program like in stdio. just a .exe file where there's printf("enter n");scanf("%d",&n)
    Hope that you get what i meant, thanks.
    Attached Images Attached Images WinAPI > C -- Executing a program-untitled-png 

  7. #7
    Registered User
    Join Date
    Dec 2018
    Posts
    5
    @GReaper, yeah i've read that but i didn't understand how to put it on my program.

  8. #8
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    It depends on how you want to do it. Are the programs compiled beforehand? If yes, CreateProcess is enough. If not, then you'll have to create a temporary source file, pass it to a compiler and then run the outputted executable.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Executing one program from within another...
    By Raigne in forum Windows Programming
    Replies: 2
    Last Post: 01-01-2007, 09:11 PM
  2. Replies: 40
    Last Post: 09-01-2006, 12:09 AM
  3. Executing a program
    By trovoada in forum C Programming
    Replies: 15
    Last Post: 07-04-2005, 06:01 AM
  4. executing another program
    By Jamsan in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2003, 08:22 PM
  5. executing program....
    By Turek in forum Windows Programming
    Replies: 6
    Last Post: 08-01-2002, 02:13 PM

Tags for this Thread