I am trying to correct a program that makes to other programs with the createProces
call.
The problem is when I pass an object of the Brick
class as a parameter of the createProcess
call.
I create the object (in the main) this way:
char IpApplicationName[1000];
STARTUPINFO StartInfo;
PROCESS_INFORMATION ProcessInfo;
strcpy(IpApplicationName, "c:\\Documents and Settings\\Eigenaar\\Bureaublad\\BluetoothTestr\\recvProc\\bin\\Debug\\recvProc.exe");
//set up the NXT
Connection *connection = new Bluetooth();
Brick *nxt = new Brick(connection);
char *nxt_ptr = (char *)&nxt;
Then I connect like this (6
is the comm port of the bluetooth dongle):
connection->connect(6);
CreateProcess(IpApplicationName, nxt_ptr, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartInfo, &ProcessInfo);
This all works fine I think, but the problem is when I cast the char*
back to the Brick
class in the recvProc.exe
process like this:
Brick *nxt = (Brick*)argv[0];
If I comment this, then the program works fine... What is wrong with this line? Or do I need to pass the Connection object in createProcess
?
You are passing, as a command line argument, a pointer to a pointer to a class. This is broken in quite a few ways:
In short, you can't pass objects as command-line arguments. Only text.
So, what do do here? Here are your options:
recvProc
into a DLL that runs inside the parent process.