Jump to content
OMRON Forums

hxbang2005

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by hxbang2005

  1. Hi everybody: Lastly, I using Pcommserver based on MFC in Visio studio 2010.Firstly, It's OK when I using it in single thread following the document 《PcommServer.pdf》, the code like this: long testInterface; IPmacDevice pmacDevice; long dwDevice; BOOL pbSuccess; CoInitialize(NULL); testInterface = pmacDevice.CreateDispatch(_T("PcommServer.PmacDevice.1")); if (!testInterface) AfxMessageBox("Can Not Connect PcommServer Interface "); I can use getresponseex() function to send command to PMAC, when I sending "I5", can response "0". All is normal when using it in the single thread. But when I create a thread using "CreateThread" function, in the thread function I have invoked the pmacDevice.GetResponseEx() to get motor's status, then it appears a error. The error is like that: Unhandled exception at 0x769dc6b4 in **_exp_platform.exe: 0xC0000005: Access violation reading location 0xfeeefeee. And program stop at "m_lpDispatch = NULL" in the"ReleaseDispatch() " function, the ReleaseDispatch() like that: void COleDispatchDriver::ReleaseDispatch() { if (m_lpDispatch != NULL) { if (m_bAutoRelease) m_lpDispatch->Release(); m_lpDispatch = NULL; } } Then I guess it cannot invoke pmacDevice's function in the another thread. I find the reason through by google, the result is that we cannot directly invoke the COM pointer in the Multi-thread. When we invoked the COM pointer in the Multi-thread, we need using GIT or Mashal technology. I am not familiar at COM technology, so does everyone encounter this problem? how to solve it? By the way, except the Pcommserver, have another method using based on MFC?such as DLL. If have, can give me an example? Thanks.
×
×
  • Create New...