johanhz
asked on
multithreaded OCX
Hi,
I wrote a multithreaded OCX (Visual C++, with the ocx wizzard).
In a second thread (buffer processing) I fire an event to tell the application that someting has to be processed. The application then call's a property, set by the OCX before firing the event.
A Visual C++ application test programm gets the correct values and runs perfect. However, a VB programm crashes when asking the property in the eventhandling. (It does not crash when it asks the property value outside the event-handling!!)
Here's some OCX code :
- creation of the second thread
AfxBeginThread((AFX_THREAD PROC)Buffe rThread, this);
- the second thread
UINT BufferThread (LPVOID pParam)
{
CPosKeyboardCtrl* pObject = (CPosKeyboardCtrl*)pParam;
if (pObject == NULL ||
!pObject->IsKindOf(RUNTIME _CLASS(CPo sKeyboardC trl)))
return 1; // if pObject is not valid // do something with 'pObject'
while (pObject->m_bOpened)
{
ResetEvent(hEventReceive);
// wait until character is received
WaitForSingleObject(hEvent Receive, INFINITE);
while (pVerwerkBuffer < pCurrentBuffer)
// we have characters to process
{
pObject->m_pOSKeyData = TheKey;
pVerwerkBuffer ++;
pObject->FireDataEvent(1);
}
pVerwerkBuffer = pBeginGlobalBuffer;
pCurrentBuffer = pBeginGlobalBuffer;
}
return TRUE;
}
I am desperate. Why does the C++ testprogramm work, but not a VB programm?
A correct and usable answer please.
JOHan
I wrote a multithreaded OCX (Visual C++, with the ocx wizzard).
In a second thread (buffer processing) I fire an event to tell the application that someting has to be processed. The application then call's a property, set by the OCX before firing the event.
A Visual C++ application test programm gets the correct values and runs perfect. However, a VB programm crashes when asking the property in the eventhandling. (It does not crash when it asks the property value outside the event-handling!!)
Here's some OCX code :
- creation of the second thread
AfxBeginThread((AFX_THREAD
- the second thread
UINT BufferThread (LPVOID pParam)
{
CPosKeyboardCtrl* pObject = (CPosKeyboardCtrl*)pParam;
if (pObject == NULL ||
!pObject->IsKindOf(RUNTIME
return 1; // if pObject is not valid // do something with 'pObject'
while (pObject->m_bOpened)
{
ResetEvent(hEventReceive);
// wait until character is received
WaitForSingleObject(hEvent
while (pVerwerkBuffer < pCurrentBuffer)
// we have characters to process
{
pObject->m_pOSKeyData = TheKey;
pVerwerkBuffer ++;
pObject->FireDataEvent(1);
}
pVerwerkBuffer = pBeginGlobalBuffer;
pCurrentBuffer = pBeginGlobalBuffer;
}
return TRUE;
}
I am desperate. Why does the C++ testprogramm work, but not a VB programm?
A correct and usable answer please.
JOHan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
pellep,
Your suggestion led me to the sollution (article ID Q157437), so i'm giving you the points.
Thanks and enjoy!
Your suggestion led me to the sollution (article ID Q157437), so i'm giving you the points.
Thanks and enjoy!
http://support.microsoft.com/support/kb/articles/Q155/6/45.asp
May be it is you case.
About Multithreading in VB see
http://msdn.microsoft.com/library/periodic/period98/vbpj0298.htm
And may be you must simple upgrade VB ? See
http://support.microsoft.com/support/kb/articles/Q171/5/54.asp
Alex