Into the registry I found that I call the com interface ThreadingModel=both , although I don't own program error, but I'm confused, not to say that needs to be done in a different thread CoInitialize? Why do I no use CoInitialize program in another thread is no problem?? The specific procedures are as follows:
In the main thread of the constructor initializes the
CFaceRecognizeCtrl: : CFaceRecognizeCtrl ()
: m_ZkFace (NULL)
{
CoInitialize (NULL);
Retrieves the hr=S_OK;
Hr=m_ZkFace. CreateInstance (__uuidof (CZKEM));//create a com object
If (hr==S_FALSE | | NULL==m_ZkFace)
{
AfxMessageBox (_T (" initialization failed!" ));
}
}
LONG CFaceRecognizeCtrl: : StartLoadUserFace (LONG m_lMachineNum)//in the function of open another thread
{
AFX_MANAGE_STATE (AfxGetStaticModuleState ());
If (NULL==m_ZkFace)
{
M_lErrorCode=1000;
return FALSE;
}
M_lMachineNumber=m_lMachineNum;
//open thread
If (m_hThread==NULL)
{
DWORD dwThreadId=0;
M_hThread=CreateThread (NULL, 0, & amp; __ThreadReadUserFace, this CREATE_SUSPENDED, & amp; DwThreadId);
}
If (m_hThread!=NULL)
{
ResumeThread (m_hThread);
Return TRUE;
}
The else
return FALSE;
}
//thread function
DWORD WINAPI ThreadReadUserFace (LPVOID lpParam)
{
CFaceRecognizeCtrl * pCRC=static_cast & lt; CFaceRecognizeCtrl * & gt; (lpParam);
While (1)
{
If (pCRC!=NULL)
{
PCRC - & gt; __ReadUserFace ();
}
}
Return TRUE;
}
Void CFaceRecognizeCtrl: : __ReadUserFace ()
{
If (NULL==m_ZkFace)
{
return;
}
if(! M_ZkFace - & gt; EnableDevice (m_lMachineNumber, FALSE {
return;
}
}
In _ReadUserFace () function I still use the main thread of the com object m_ZkFace, also don't have any strange?? I want to know is why?? Where is the master?? Come quickly!!
CodePudding user response:
Master ah?? How no one reply