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. C / C++ / MFC
  4. kill COM calls in thread

kill COM calls in thread

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncomsecurity
12 Posts 3 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.
  • T ThatsAlok

    viperlogic wrote:

    what is the best way of killing a thread from outside the thread, i am using TerminateThread() but i dont think this is the best way??

    Set a boolean varible depending on it state terminate the thread

    V Offline
    V Offline
    viperlogic
    wrote on last edited by
    #3

    what command do i use to kill the thread thou from outside the thread?

    T 1 Reply Last reply
    0
    • V viperlogic

      what command do i use to kill the thread thou from outside the thread?

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #4

      viperlogic wrote:

      what command do i use to kill the thread thou from outside the thread?

      same, change the value of boolean variable from outside, which thread is checking from inside...

      V 1 Reply Last reply
      0
      • V viperlogic

        i have a thread that calls the following CoInitializeEx() CoInitializeSecurity() CoCreateInstance() ConnectServer() if the thread isnt successful in 3secs (using WaitForSingleObject(pThread->m_hThread, 3000)) it is closed. what is the best way of killing a thread from outside the thread, i am using TerminateThread() but i dont think this is the best way?? it appears thou that the calls in the thread are not being killed off because if i go to start the thread again CoInitializeSecurity() throws up an error saying that it cant initialize security. so iam assuming it is saying this because the thread wasnt killed off right plz help

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #5

        viperlogic wrote:

        what is the best way of killing a thread from outside the thread...

        See here.


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        V 1 Reply Last reply
        0
        • T ThatsAlok

          viperlogic wrote:

          what command do i use to kill the thread thou from outside the thread?

          same, change the value of boolean variable from outside, which thread is checking from inside...

          V Offline
          V Offline
          viperlogic
          wrote on last edited by
          #6

          sorry, i dont understand, example please thanks

          1 Reply Last reply
          0
          • D David Crow

            viperlogic wrote:

            what is the best way of killing a thread from outside the thread...

            See here.


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "There is no death, only a change of worlds." - Native American Proverb

            V Offline
            V Offline
            viperlogic
            wrote on last edited by
            #7

            so i use the following to delete a thread from outside?? Does "delete pThread" call ExitThread?? switch(WaitForSingleObject(pThread->m_hThread, 3000)) { case WAIT_TIMEOUT: { delete pThread; break; } case WAIT_OBJECT_0: { // thread has terminated on its own break; } }

            D 1 Reply Last reply
            0
            • V viperlogic

              so i use the following to delete a thread from outside?? Does "delete pThread" call ExitThread?? switch(WaitForSingleObject(pThread->m_hThread, 3000)) { case WAIT_TIMEOUT: { delete pThread; break; } case WAIT_OBJECT_0: { // thread has terminated on its own break; } }

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #8

              viperlogic wrote:

              Does "delete pThread" call ExitThread??

              No. At the point in which you are deleting pThread, the thread has already terminated. You are just cleaning up the CWinThread object. ExitThread() is called from within the secondary thread, unlike TerminateThread() which is called from outside the secondary thread.


              "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

              "There is no death, only a change of worlds." - Native American Proverb

              V 1 Reply Last reply
              0
              • D David Crow

                viperlogic wrote:

                Does "delete pThread" call ExitThread??

                No. At the point in which you are deleting pThread, the thread has already terminated. You are just cleaning up the CWinThread object. ExitThread() is called from within the secondary thread, unlike TerminateThread() which is called from outside the secondary thread.


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "There is no death, only a change of worlds." - Native American Proverb

                V Offline
                V Offline
                viperlogic
                wrote on last edited by
                #9

                i think i have that working now. A kind of related problem i have is with the code below. This is a part of the code the thread executes, if sucessful all is ok. this thread has a timeout of 3secs. A problem is that the ConnectServer call below takes 2minutes to complete if it cant connect. when this happens the below messagebox pops ups and then the program crashes. is it crashing because the code wants to "return" but there is nothing to return to as the thread has been already killed?? How can i modify it so that it wont crash. A message box doesnt have to be displayed either. many thanks hres = pLoc_test->ConnectServer( _bstr_t(L"\\\\"+strIP1+"\\root\\cimv2"), // Object path of WMI namespace NULL, // User name. NULL = current user NULL, // User password. NULL = current 0, // Locale. NULL indicates current WBEM_FLAG_CONNECT_USE_MAX_WAIT, // Security flags 0, // Authority 0, // Context object &pSvc_test // pointer to IWbemServices proxy ); if (FAILED(hres)) { char error_msg[64]; sprintf(error_msg, "wmi_test: Could not connect. Error code = 0x%x", hres); MessageBox(error_msg , "Error" , MB_ICONERROR | MB_OK); pLoc_test->Release(); return; }

                D 1 Reply Last reply
                0
                • V viperlogic

                  i think i have that working now. A kind of related problem i have is with the code below. This is a part of the code the thread executes, if sucessful all is ok. this thread has a timeout of 3secs. A problem is that the ConnectServer call below takes 2minutes to complete if it cant connect. when this happens the below messagebox pops ups and then the program crashes. is it crashing because the code wants to "return" but there is nothing to return to as the thread has been already killed?? How can i modify it so that it wont crash. A message box doesnt have to be displayed either. many thanks hres = pLoc_test->ConnectServer( _bstr_t(L"\\\\"+strIP1+"\\root\\cimv2"), // Object path of WMI namespace NULL, // User name. NULL = current user NULL, // User password. NULL = current 0, // Locale. NULL indicates current WBEM_FLAG_CONNECT_USE_MAX_WAIT, // Security flags 0, // Authority 0, // Context object &pSvc_test // pointer to IWbemServices proxy ); if (FAILED(hres)) { char error_msg[64]; sprintf(error_msg, "wmi_test: Could not connect. Error code = 0x%x", hres); MessageBox(error_msg , "Error" , MB_ICONERROR | MB_OK); pLoc_test->Release(); return; }

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  Since you are using WBEM_FLAG_CONNECT_USE_MAX_WAIT, why not set your WaitForSingleObject() call to also wait for 2 minutes (or a little more)?


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "There is no death, only a change of worlds." - Native American Proverb

                  V 1 Reply Last reply
                  0
                  • D David Crow

                    Since you are using WBEM_FLAG_CONNECT_USE_MAX_WAIT, why not set your WaitForSingleObject() call to also wait for 2 minutes (or a little more)?


                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                    "There is no death, only a change of worlds." - Native American Proverb

                    V Offline
                    V Offline
                    viperlogic
                    wrote on last edited by
                    #11

                    i am scanning alot of hosts with this app, waiting 2mins for every host would take for ever to scan the network, hence i use the thread timeout of 3secs i just read about _endthread and it appears to work so far. is this a proper solution?

                    D 1 Reply Last reply
                    0
                    • V viperlogic

                      i am scanning alot of hosts with this app, waiting 2mins for every host would take for ever to scan the network, hence i use the thread timeout of 3secs i just read about _endthread and it appears to work so far. is this a proper solution?

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #12

                      viperlogic wrote:

                      i am scanning alot of hosts with this app, waiting 2mins for every host would take for ever to scan the network, hence i use the thread timeout of 3secs

                      I did something very similar to this in a ping-type application. For each machine that I was going to ping, I just created a secondary thread and put the ping-related code in it. Given that the machines each responded in their own time, the threads all completed at different times; some were instantaneous while others took a lot longer. If your UI has some sort of listbox or list control for these machines, give them a default status of "Establishing connection. Please wait...". When that machine's thread terminates, replace the default status with what actually happened.

                      viperlogic wrote:

                      i just read about _endthread and it appears to work so far. is this a proper solution?

                      Not unless you also used _beginthread(). Regardless, it is called from within the secondary thread. Terminating a thread from within itself is vastly different than terminating a thread from some other thread.


                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                      "There is no death, only a change of worlds." - Native American Proverb

                      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