Hi everybody!

I am having some trouble running a detached process using CreateProcess function in C++.

I have been using the following function to spawn processes in c++ for years now havnig no trouble. I have used it with console applications, mfc apps, dialog based ... etc :

StartProc(char *callprogram, bool blshow)
{
        //callprogam = full path to executable
        //blshow = show or hide application's window
         STARTUPINFO startInfo;
         PROCESS_INFORMATION procInfo;
         DWORD       creationFlags;
         startInfo.cb = sizeof(STARTUPINFO);
         startInfo.lpReserved = NULL;
         startInfo.lpDesktop = NULL;
         startInfo.lpTitle = NULL;
         startInfo.dwFlags = STARTF_USESHOWWINDOW;
         if (blshow==true) startInfo.wShowWindow = SW_SHOW;
                 else startInfo.wShowWindow = SW_HIDE;
         startInfo.cbReserved2 = 0;
         startInfo.lpReserved2 = NULL;
         creationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
        //-----------------
                 printf("%s",callprogram);
        if( !CreateProcess(NULL,callprogram, NULL, NULL, TRUE, 
        creationFlags, NULL, NULL, &startInfo, &procInfo) )
            AfxMessageBox("Process create failed",MB_ICONERROR, NULL);
}

For the first time i have trouble executing a java application which is wrapped to an executable using jsmooth.
CreateProcess returns no errors but the java app exits immediately after creation.

The java application is a fullscreen application using Java OpenGL wrapper.

I messed around with dwFlags and creation flags but no luck...

Any advice?
Thanks in advance.

Ohhh shooot...
Just figured it out! Always do, a couple of minutes after i post...

I had to change the current working directory, or else the java app cannot find the java libraries etc...

Just Added : SetCurrentDirectory("c:\mypath\etc\");
and problem solved...

Thanks and sorry for the waste of bytes..
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.