Lunch rfactor from another application

carruba74

hi to all,
in this day i try to write a small application that must lunch the rfactor game

I write this application into a c++ language.

I try to use two methods, but i reached the same result : the rfactor start, choose all the thing into menu, ecc ecc... without problem, but when i go to track, the game closed without any message, dont' appears the loading screen of the track

If i lunch directly the same installation with rfactor.exe, i have no problem, that means that the installation is ok.

This is the code that i used

first one

Code:
SetCurrentDir(Game->Game_Path);
int result = spawnl(P_NOWAIT    , Path_rFactor.c_str(), Path_rFactor.c_str(), NULL);
if (result == -1)
{
    perror("Error from spawnl");
}

second one

Code:
SetCurrentDir(Game->Game_Path);

STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);

int res = CreateProcess(Path_rFactor.c_str(), 0, 0, 0, 0, 0, 0, 0, &si, &pi);

have you an idea to solve the problem??

ciauzz
 
Hi Carru,

I had to do so similar and I solved it with the following function:

Code:
    Function StartMainApplication() As String
        Dim clsProcess As New Process()
        clsProcess.StartInfo.FileName = sExecutable
        If checkboxFullproc.Checked = True Then
            ' -- Debug.Print("use +fullproc")
            ' -- clsProcess.StartInfo.Arguments = "+fullproc" ' -- warning - added 08.09.2009 !!!
        End If
        clsProcess.StartInfo.WorkingDirectory = sMainDirectory
        clsProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
        clsProcess.Start()
        ' -- clsProcess.WaitForInputIdle(10000) ' -- warning - added 04.09.2009 !!!
        Return clsProcess.Id.ToString()
    End Function

I know it is not C++, but maybe you can adopt some for your needs !?!?

Cheers
Frank

EDIT: clsProcess.StartInfo.WorkingDirectory = sMainDirectory is the full path to rFactor root NOT its relative path ... same with sExecutable
 
Last edited:
many thanks frank.

i try to setup in the same way for c++ but not work correctly, the problem is the same.

but i try to another solution

Code:
AnsiString tmp = Game->Game_Path+"\\run.bat";

                    STARTUPINFO si;
                    PROCESS_INFORMATION pi;

                    memset(&pi, 0, sizeof(pi));
                    memset(&si, 0, sizeof(si));
                    si.cb = sizeof(si);

                    si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USEPOSITION;
                    si.wShowWindow = SW_HIDE;

                    int res = CreateProcess(tmp.c_str(), NULL, NULL, NULL, 0, 0, NULL, Game->Game_Path.c_str(), &si, &pi);

into the file run.bat, i wrote simply "rfactor.exe" and with my application i run directly this bat file.
In this way the game started and when i go to the track, load correctly.

I don't know why the fist method don't run, but with the last one the game run without problem.

ciauzz
 
... yeah, not the real elegant way to use a batch file, but hey ... if it pays the bill !?!? Who cares :)

A presto ragazzo
 
It behaves like missing working directory set. It was realy missing in your first example
In second one you pass Game->Game_Path.c_str() - but we don't know what is the value.

Link works because it has ability to change working path (by default path to linked prog is defined - check properties)
 
yes... of course Maxym.

the value Game->Game_Path contains exactly the path of the folder, absolute path, of the game.
I put into GamePathComplete = Game->Game_Path+"\\rfactor.exe"

i try to lunch with the instruction

Code:
int res = CreateProcess(GamePathComplete .c_str(), NULL, NULL, NULL, 0, 0, NULL, Game->Game_Path.c_str(), &si, &pi);

but also in this way the lunch have the same problem, game running, make all configuration, change mod, ecc ecc, but when i lunch to load a track the game closed.

the bat file is not elegant, i know, but now work well.... if i find a solution i'll write here.

many thanks.

ciauzzz
 

Back
Top