I'm trying to pass a mutex handle, to a child process trough command line, or any other way.
How can I do that? How do I acess the mutex from the child?
This is how I'm creating the child process:
HANDLE ghMutex;
if( !CreateProcess( _T("C:\\Users\\Kumppler\\Documents\\Visual Studio 2010\\Projects\\teste3\\Debug\\teste3.exe"), // No module name (use command line)
aux2, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
TRUE, // Set handle inheritance to TRUE
STARTF_USESTDHANDLES, // inherit the standard input, standard output, and standard error handles
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si[j], // Pointer to STARTUPINFO structure
&pi[j] ) // Pointer to PROCESS_INFORMATION structure
)
EDIT:
I need to use the mutex for more than one child process, is it ok?
So here is what I'm doing right now:
HANDLE ghMutex;
int mutex;
char mutexstring[7];
mutex=(int)ghMutex;
itoa(mutexValue,mutexString,10);
I'll pass the mutexString trough command line, and then convert it back at child process:
mutexValue=atoi(argv[2]);
Mutex=(HANDLE)mutexValue;
My question, is it okay to do the (HANDLE) casting??