about launching external application

This is a discussion on about launching external application within the Windows Programming forums, part of the Platform Specific Boards category; Hi Iīm noob in programming so keep it simple thank you. My OS is Vista x64 SP1 and I use ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    about launching external application

    Hi
    Iīm noob in programming so keep it simple thank you.

    My OS is Vista x64 SP1
    and I use VS 2008 PRO SP1

    I am experimenting windows programming and I thought to make a simple launcher.

    There are two functions / APIs:

    CreateProcess () and system ()

    Any other APIs???
    I got a hint that there would be more.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Really I wouldn't think there would be more APIs than the C standard libraries (system) and the Win32 API. Granted there are other functions in the Win32 API then CreateProcess (ShellExecute I think is another) -- you can find out all the stuff from that API at msdn.microsoft.com.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    8
    Yeah, I came here because I got private message in my email

    somebody called ?macro32? if I remember right and told that there would be more this kind of APIs. He suggested to subscribe in news://comp.os.ms-windows.programmer.win32

    But I didnīt manage, some kind Windows mail window opens and when trying to subscribe it just loads..

    thatīs why I tried other forums with separate Windows coding area..this is NO spamming if you are wondering.

    so Iīll check ShellExecute too....
    Last edited by sydetys; 01-03-2009 at 03:17 PM.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    If you just want to read news, then http://groups.google.com/

    But for most effective use, a newsreader (there are many) is a good start - http://en.wikipedia.org/wiki/List_of_Usenet_newsreaders

    Some web browsers can read the news, as can some email clients, but they tend to be a compromise.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Use ShellExecute, but I you want to keep track of the process ID and thread ID, use CreateProcess.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    To subscribe newsgroups with Windows Mail :
    http://support.cox.com/sdccommon/asp...b-9ad40513af96

  8. #8
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    Progress....a little

    Thaats it. I have tried much so I give up.
    Learning native c++ didnīt pay up. Coding windows is like starting from clean table.

    my code this far is like this:

    Code:
    #include<windows.h>
    #include<stdio.h>
    #include<tchar.h>
    
    
    void _tmain( int argc, TCHAR *argv [] )
    {
    	STARTUPINFO si;
        PROCESS_INFORMATION pi;
    	STARTUPINFO sj;
        PROCESS_INFORMATION pj;
    
        ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );
    	ZeroMemory( &sj, sizeof(sj) );
        sj.cb = sizeof(sj);
        ZeroMemory( &pj, sizeof(pj) );
      
    	// Start the child process. 
    	if( !CreateProcess( NULL,
    		"A.exe",							// Command line
            NULL,									// Process handle not inheritable
            NULL,									// Thread handle not inheritable
            FALSE,									// Set handle inheritance to FALSE
            0,										// No creation flags
            NULL,									// Use parent's environment block
            NULL,									// Use parent's starting directory 
            &si,									// Pointer to STARTUPINFO structure
            &pi )									// Pointer to PROCESS_INFORMATION structure
        ) 
       
    	
    
    if (pi.hProcess != 0)
    
    	ResumeThread (pj.hThread);
    
        WaitForSingleObject( pi.hProcess, INFINITE );
    
      
        CloseHandle( pi.hProcess );
        CloseHandle( pi.hThread );
    
    
    if( !CreateProcess( NULL,
    		"B.exe",							
            NULL,								
            NULL,									
            FALSE,									
            CREATE_SUSPENDED,										
            NULL,									
            NULL,									
            &sj,									
            &pj )									
        ) 
    
    ...............................the rest is obvious....}
    now both applications (A and B) opens a window but simultaneusly, so I suspended one thread.

    and now I have to resume suspended thread. I have tried everything:

    ResumeThread (sj. / pj.hthread / .process and tried putting &sj/&pj...

    Should I add more parameters in STARTUPINFO or PROCESS_INFORMATION?

    no luck, so what is that handle which is importatnt for resumethread?

    thanx and sorry being noob.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What do you think CreateThread returns, if not a handle to the thread?

    (Edit: And I hope you actually have error-handling stuff inside that if statement there, as opposed to the nothing you've posted?)
    Last edited by tabstop; 01-04-2009 at 01:50 PM.

  10. #10
    Registered User
    Join Date
    Jan 2009
    Posts
    8
    Quote Originally Posted by tabstop View Post
    What do you think CreateThread returns, if not a handle to the thread?

    (Edit: And I hope you actually have error-handling stuff inside that if statement there, as opposed to the nothing you've posted?)
    no error handling, and if I remove that "if ()" function and leave only ResumeThread () it wonīt do anything.. at least it get compiled just fine but resuming wonīt happen..that piece of code is just leftover what I have been testing. Something similar I need.

    Well... if I think hard,. only thread which would be resumed is pj.thread, isnīt that right?

    but I want so that only when pi.thread had been fully completed. yes? that means handle in 1st child thread is "> 0" or "!= 0" or do I have to use STILL_ACTIVE flag?...hmm or sj.cb..have to try that next..I have overlooked that one..
    Last edited by sydetys; 01-04-2009 at 03:23 PM. Reason: new things

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    1. Well, if you have an if, then the next statement is going to be the "then" part of it -- so look into that (since I have no idea what your code looks like or what you're trying to do).

    2. So you suspended B, I guess, looking at your CreateThread calls -- which means you sure as heck can't resume it until after you've even created it and suspended it, yes? You can't resume A -- it's still running.

  12. #12
    Registered User
    Join Date
    Jan 2009
    Posts
    8
    Quote Originally Posted by tabstop View Post
    1. Well, if you have an if, then the next statement is going to be the "then" part of it -- so look into that (since I have no idea what your code looks like or what you're trying to do).

    2. So you suspended B, I guess, looking at your CreateThread calls -- which means you sure as heck can't resume it until after you've even created it and suspended it, yes? You can't resume A -- it's still running.
    Right, I want to run 1st child process 1st (with A.exe), that one which isnīt suspended,
    thatīs why I put pj.Thread in ResumeThread function. Logically it should unsuspend 2nd child process (B.exe in it)

    ..Maybe I just should move CloseHandle()īs to the very end of code....

    But like I said earlier if I remove IF () function ResumeThread wonīt unsusped 2nd child process. Even if moved to end of code..it would be enough if I would be positive that Resuming would work then I would work on that IF () function more..

    Am I even close?

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't think you're particularly close, given what you've posted, no. How do you propose to unsuspend the second child process when you haven't even created it yet?

  14. #14
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    Oh my god..

    I...got it WORKING!!

    yeeah NOW I can be sure that all my functions work, final thing would be insert taht conditional IF () struct in, I had to shuffle lines a bit....order of code lines are MORE strict than I thought.

    Thanks Tabstop your hints gave the right path, Iīll be back if I canīt make IF function work right.

  15. #15
    Registered User
    Join Date
    Jan 2009
    Posts
    8

    unnessesary work

    I managed to simplify that code, no suspending needed after all
    Just removed IF(!) structs from code (which was copy/pasted from msdn and then worked)

    after that WaitForSingleObject () did the work fine BUT

    now after final child process, before program is closed, console windows appears, blank.
    Why is it appearing? I tried CREATE_NO_WINDOW, and moved A and B.EXE as 1st parameter in CreateProcess() function, didnīt help.

    Any hints how to fix this?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Position mouse in external application
    By keira in forum C# Programming
    Replies: 1
    Last Post: 09-15-2008, 08:05 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21