Problem with ATL COM Dll.... Firing event in thread
-
Hi, I am using the ATL COM DLL. In this I am createng two threads. I have added new ATL object which supports connceting point, appartment thereaded model, Dual interface and agregation=yes. While creating thread and passing the interface pointer as this pointer. hStatusThread = CreateThread(NULL, o, LPTHREAD_START_ROUTINE(StatusThread), (LPVOID)this, 0, &dwThStId); ::SetThreadPriority(hStatusThread, THREAD_PRIORITY_HIGHEST); I am accessing the interface pointer in thread and firing the event.. UINT StatusThread(LPVOID param) { CMyConnectObj *ptrObj = NULL; ptrObj = (CMyConnectObj*)param; if(ptrObj == NULL) return 0; if(WaitForSingleObject(g_Mutex,INFINITE) == WAIT_OBJECT_0) { ptrObj->Fire_ErrorCode(lErrorCode); ReleaseMutex(g_Mutex); } } I am using vb6.0 client to use this dll. but while firing event at line i ptrObj->Fire_ErrorCode(lErrorCode); it's giving error as "Unhandled Exception in ConnectProg.exe (MSVBVM60.dll)0x0000005: Access Violation. But if I tried to fire event for one of the ATL object function there is no problem at all. Please help me for this with perect solution.. It's very urgent.
-
Hi, I am using the ATL COM DLL. In this I am createng two threads. I have added new ATL object which supports connceting point, appartment thereaded model, Dual interface and agregation=yes. While creating thread and passing the interface pointer as this pointer. hStatusThread = CreateThread(NULL, o, LPTHREAD_START_ROUTINE(StatusThread), (LPVOID)this, 0, &dwThStId); ::SetThreadPriority(hStatusThread, THREAD_PRIORITY_HIGHEST); I am accessing the interface pointer in thread and firing the event.. UINT StatusThread(LPVOID param) { CMyConnectObj *ptrObj = NULL; ptrObj = (CMyConnectObj*)param; if(ptrObj == NULL) return 0; if(WaitForSingleObject(g_Mutex,INFINITE) == WAIT_OBJECT_0) { ptrObj->Fire_ErrorCode(lErrorCode); ReleaseMutex(g_Mutex); } } I am using vb6.0 client to use this dll. but while firing event at line i ptrObj->Fire_ErrorCode(lErrorCode); it's giving error as "Unhandled Exception in ConnectProg.exe (MSVBVM60.dll)0x0000005: Access Violation. But if I tried to fire event for one of the ATL object function there is no problem at all. Please help me for this with perect solution.. It's very urgent.
chetanjoshi9 wrote:
THREAD_PRIORITY_HIGHEST
That's a bit evil for a start - you really don't want to be altering thread priorities.
chetanjoshi9 wrote:
MSVBVM60
That's likely your problem - your contorl might be thread aware, but I don't think VB6 is...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
chetanjoshi9 wrote:
THREAD_PRIORITY_HIGHEST
That's a bit evil for a start - you really don't want to be altering thread priorities.
chetanjoshi9 wrote:
MSVBVM60
That's likely your problem - your contorl might be thread aware, but I don't think VB6 is...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
what is mean by thread aware?
-
what is mean by thread aware?
Your control is aware that there can be more more than one thread, and deals with that. Visual Basic doesn't.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Your control is aware that there can be more more than one thread, and deals with that. Visual Basic doesn't.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
please tell me the settings required while creating the new ATL object if we want to fire event within the thread....
-
please tell me the settings required while creating the new ATL object if we want to fire event within the thread....
First thing to try - you need to call CoInitializeEx[^] on the StatusThread, that way your event firing might be marshalled across into the VB thread. Otherwise...have you thought about firing the event on the other thread, you know, the one VB calls?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
First thing to try - you need to call CoInitializeEx[^] on the StatusThread, that way your event firing might be marshalled across into the VB thread. Otherwise...have you thought about firing the event on the other thread, you know, the one VB calls?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
hStatusThread = CreateThread(NULL, 0, LPTHREAD_START_ROUTINE(StatusThread), (LPVOID)this, 0, (LPDWORD)&dwStID); ::SetThreadPriority(hStatusThread, THREAD_PRIORITY_HIGHEST); UINT StatusThread(LPVOID param) { MSG msg; CMyTestObj *ptrObj = (CMyTestObj*)param; while(1) { if(!GetMessage(&msg, NULL, 0, 0)) return 0; switch(msg.message) { case START_COMMAND: ptrObj->Fire_ErrorCode(123); break; } } } This is my code I am firing event in thread as PostThreadMessage(dwStID, START_COMMAND, NULL, NULL); but application crashes at line "ptrObj->Fire_ErrorCode(123);" But if fire event in any member function (without thread) it works fine.. Please help me for this.. it's very urgent Thanks.
-
hStatusThread = CreateThread(NULL, 0, LPTHREAD_START_ROUTINE(StatusThread), (LPVOID)this, 0, (LPDWORD)&dwStID); ::SetThreadPriority(hStatusThread, THREAD_PRIORITY_HIGHEST); UINT StatusThread(LPVOID param) { MSG msg; CMyTestObj *ptrObj = (CMyTestObj*)param; while(1) { if(!GetMessage(&msg, NULL, 0, 0)) return 0; switch(msg.message) { case START_COMMAND: ptrObj->Fire_ErrorCode(123); break; } } } This is my code I am firing event in thread as PostThreadMessage(dwStID, START_COMMAND, NULL, NULL); but application crashes at line "ptrObj->Fire_ErrorCode(123);" But if fire event in any member function (without thread) it works fine.. Please help me for this.. it's very urgent Thanks.
No, that's not what I said, is it. Did I say something about adding a
CoInitializeEx
to StatusThread? Yes, I think I did. Try that first, it may enable the COM runtime to marshall the event fire across to the VB thread.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
No, that's not what I said, is it. Did I say something about adding a
CoInitializeEx
to StatusThread? Yes, I think I did. Try that first, it may enable the COM runtime to marshall the event fire across to the VB thread.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
please tell me how to use CoInitialzeEx() on StatusThread.. I am not getting.... Please...
-
please tell me how to use CoInitialzeEx() on StatusThread.. I am not getting.... Please...
Go away and learn about how COM and threads interact[^]. You need to understand this stuff before you try messing with COM and threads.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p