Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Problem with COM DLL---- Firing event in thread

Problem with COM DLL---- Firing event in thread

Scheduled Pinned Locked Moved COM
helpc++com
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chetanjoshi9
    wrote on last edited by
    #1

    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.

    R 1 Reply Last reply
    0
    • C chetanjoshi9

      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.

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      chetanjoshi9 wrote:

      But if I tried to fire event for one of the ATL object function there is no problem at all.

      This is due to the fact that you have not initialized COM for your new apartment, i.e. in your worker thread. You have to call ::CoInitialize() before using any COM functionality from your worker thread. Don't forget to place a matching call to ::CoUninitialize() before exiting your worker thread. When you've done that you will hit another problem since you're trying to call the interface to the client's event sink from another apartment than it belongs to. You have to marshal the events sink interface to the apartment of your worker thread. Have a look at Michael Lindig's solution for that here[^]. It uses the GIT (Global Interface Table) for that and you'll be able to fire your events from any apartment.

      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups