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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Problem with ATL COM Dll.... Firing event in thread

Problem with ATL COM Dll.... Firing event in thread

Scheduled Pinned Locked Moved ATL / WTL / STL
helpc++com
10 Posts 2 Posters 10 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.

    S 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.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • S Stuart Dootson

        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

        C Offline
        C Offline
        chetanjoshi9
        wrote on last edited by
        #3

        what is mean by thread aware?

        S 1 Reply Last reply
        0
        • C chetanjoshi9

          what is mean by thread aware?

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • S Stuart Dootson

            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

            C Offline
            C Offline
            chetanjoshi9
            wrote on last edited by
            #5

            please tell me the settings required while creating the new ATL object if we want to fire event within the thread....

            S 1 Reply Last reply
            0
            • C chetanjoshi9

              please tell me the settings required while creating the new ATL object if we want to fire event within the thread....

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              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

              C 1 Reply Last reply
              0
              • S Stuart Dootson

                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

                C Offline
                C Offline
                chetanjoshi9
                wrote on last edited by
                #7

                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.

                S 1 Reply Last reply
                0
                • C chetanjoshi9

                  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.

                  S Offline
                  S Offline
                  Stuart Dootson
                  wrote on last edited by
                  #8

                  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

                  C 1 Reply Last reply
                  0
                  • S Stuart Dootson

                    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

                    C Offline
                    C Offline
                    chetanjoshi9
                    wrote on last edited by
                    #9

                    please tell me how to use CoInitialzeEx() on StatusThread.. I am not getting.... Please...

                    S 1 Reply Last reply
                    0
                    • C chetanjoshi9

                      please tell me how to use CoInitialzeEx() on StatusThread.. I am not getting.... Please...

                      S Offline
                      S Offline
                      Stuart Dootson
                      wrote on last edited by
                      #10

                      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

                      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