Bad Thread ID from CreateProcess() 
Author Message
 Bad Thread ID from CreateProcess()

I'm trying to create a process that I can post messages to in order to
signal it...  GetLastError() reports Bad Thread ID.

Here's what I use:

STARTUPINFO suInfo;
memset( &suInfo, 0, sizeof( suInfo ) );
suInfo.cb = sizeof( suInfo );
PROCESS_INFORMATION procInfo;
TCHAR* l_szAppName = _T("mychildexecutable.exe");
TCHAR* l_szAppCommandLine = _T("");
m_hChildProcessThread = NULL;
if( FALSE == ::CreateProcess( l_szAppName, l_szAppCommandLine, NULL, NULL,
FALSE, CREATE_NO_WINDOW|NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo,
&procInfo ) )
{
MessageBox( "ERROR: Could not launch AgentServer for Demo" );

Quote:
}

//Store the thread so we can send it requests
m_hChildProcessThread = procInfo.hThread;
ASSERT( m_hChildProcessThread );
//Tell the AgentServer to move the agent to the correct position
if( FALSE == ::PostThreadMessage( hChildProcessThread, WM_QUIT, 0, 0 ) )
{
MessageBox( "FAILED POST THREAD MESSAGE" );

Quote:
}

    Thanks,
            WTH


Sun, 11 Sep 2005 22:46:37 GMT  
 Bad Thread ID from CreateProcess()


Quote:
> I'm trying to create a process that I can post messages to in order to
> signal it...  GetLastError() reports Bad Thread ID.

> Here's what I use:

> STARTUPINFO suInfo;
> memset( &suInfo, 0, sizeof( suInfo ) );
> suInfo.cb = sizeof( suInfo );
> PROCESS_INFORMATION procInfo;
> TCHAR* l_szAppName = _T("mychildexecutable.exe");
> TCHAR* l_szAppCommandLine = _T("");
> m_hChildProcessThread = NULL;
> if( FALSE == ::CreateProcess( l_szAppName, l_szAppCommandLine, NULL, NULL,
> FALSE, CREATE_NO_WINDOW|NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo,
> &procInfo ) )
> {
> MessageBox( "ERROR: Could not launch AgentServer for Demo" );
> }
> //Store the thread so we can send it requests
> m_hChildProcessThread = procInfo.hThread;
> ASSERT( m_hChildProcessThread );
> //Tell the AgentServer to move the agent to the correct position
> if( FALSE == ::PostThreadMessage( hChildProcessThread, WM_QUIT, 0, 0 ) )
> {
> MessageBox( "FAILED POST THREAD MESSAGE" );
> }

According to the docs, the target thread must have created its message queue
before PostThreadMessage will work. If the app is still starting up, it may
not have entered its message loop yet. Perhaps calling
WaitForInputIdle(procInfo.hProcess, 10*1000 /*or INFINITE, if you trust*/);
will help.

Jay



Sun, 11 Sep 2005 23:05:53 GMT  
 Bad Thread ID from CreateProcess()
WaitForInputIdle didn't work, but telling the thread that created the
process to Sleep a little did.

    Thanks for the pointer :)

        WTH


Quote:



> > I'm trying to create a process that I can post messages to in order to
> > signal it...  GetLastError() reports Bad Thread ID.

> > Here's what I use:

> > STARTUPINFO suInfo;
> > memset( &suInfo, 0, sizeof( suInfo ) );
> > suInfo.cb = sizeof( suInfo );
> > PROCESS_INFORMATION procInfo;
> > TCHAR* l_szAppName = _T("mychildexecutable.exe");
> > TCHAR* l_szAppCommandLine = _T("");
> > m_hChildProcessThread = NULL;
> > if( FALSE == ::CreateProcess( l_szAppName, l_szAppCommandLine, NULL,
NULL,
> > FALSE, CREATE_NO_WINDOW|NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo,
> > &procInfo ) )
> > {
> > MessageBox( "ERROR: Could not launch AgentServer for Demo" );
> > }
> > //Store the thread so we can send it requests
> > m_hChildProcessThread = procInfo.hThread;
> > ASSERT( m_hChildProcessThread );
> > //Tell the AgentServer to move the agent to the correct position
> > if( FALSE == ::PostThreadMessage( hChildProcessThread, WM_QUIT, 0, 0 ) )
> > {
> > MessageBox( "FAILED POST THREAD MESSAGE" );
> > }

> According to the docs, the target thread must have created its message
queue
> before PostThreadMessage will work. If the app is still starting up, it
may
> not have entered its message loop yet. Perhaps calling
> WaitForInputIdle(procInfo.hProcess, 10*1000 /*or INFINITE, if you
trust*/);
> will help.

> Jay



Sun, 11 Sep 2005 23:31:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting thread id from inside the thread

2. Thread/CreateProcess Help Please !

3. CreateProcess in dll thread

4. Thread\CreateProcess Help please.

5. Q: Multithreading (bad point of thread interruption)

6. Bad thread coding, mangement or something

7. Good or Bad Thread Design?

8. Incredible bad performance of Windows Threads..

9. Bad thread coding, mangement or something

10. CreateProcess in CreateProcess

11. Thread id

12. Thread id

 

 
Powered by phpBB® Forum Software