Launching an application from my program

This is a discussion on Launching an application from my program within the Windows Programming forums, part of the Platform Specific Boards category; I've gone over the FAQ regarding this issue, but I can't get the Windows implementation method to work. I think ...

  1. #1
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26

    Launching an application from my program

    I've gone over the FAQ regarding this issue, but I can't get the Windows implementation method to work. I think I know why, but I'm not sure how to go about getting around it.

    I'm trying to allow the user to launch an external application once they are done with the current one (launch it from the current app). I have a MessageBox() control, and if they choose yes I run a function with CreateProcess() to launch the program by passing the filepath of a JAR File.

    I've been looking around for a solution all afternoon, and I've looked up about the JAR format. I guess since it's a container-like file associated with the Java runtime environment (and thus only able to be launched through file ext association), I can't launch it independently from my program. But there has to be a way around this.

    Does anyone have any suggestions?
    Last edited by tao; 07-03-2006 at 04:34 PM.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    .jar files are not executable. I believe the normal way is to start java.exe, with the jar file being a parameter. Most java programs in Windows usually have a batch file - see how it lauches the application, and replicate that. (I think it's something like "java.exe -classpath JARFILE", but don't quote me on that.)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26
    Thanks for the help. I guess I didn't understand the parameters properly on the MSDN page.

    The correct code to launch it turns out to be:

    Code:
    CreateProcess(NULL,"javaw -jar \"C:\\PATH TO FILE\\JAVAAPP.jar\"",NULL,NULL,
                  FALSE,0,NULL,NULL,&startupInfo,&processInfo);
    But I was trying to split up the java executable and the arguments incorrectly as:

    Code:
    CreateProcess("javaw", "-jar \"C:\\PATH TO FILE\\JAVAAPP.jar\"",NULL,NULL,
                  FALSE,0,NULL,NULL,&startupInfo,&processInfo);

    Thanks again for the help. =]

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Did you try using ShellExecute? Something like:
    Code:
    ShellExecute(0,0,"JAVAAP.jar",0,"c:\\path",SW_SHOW);
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26
    I didn't, but could you elaborate on potential benefits versus CreateProcess?
    I'd like to use the most applicable solution for my situation.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Assuming javaw is associated with .jar files, you should be able to pass the name of the .jar file to ShellExecute and not bother with calling javaw directly.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    tao
    tao is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    26
    javaw.exe is equivalent to java.exe but there's no console window launched when called.

    See reference if you're curious. Nothing fancy about it really (literally).

    ShellExecute does sound plausible. I'll give it a shot, thanks.

    Edit: It works great, too. Cheers.
    Last edited by tao; 07-04-2006 at 02:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Launching a program on startup
    By beanroaster in forum C++ Programming
    Replies: 5
    Last Post: 05-20-2006, 02:21 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Need Delimiter Program helpful hints.
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 02-16-2002, 06:27 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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