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. threading problems

threading problems

Scheduled Pinned Locked Moved COM
c++comsysadminhelpquestion
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.
  • D Offline
    D Offline
    Dietmar Goetz
    wrote on last edited by
    #1

    I want to use my exe-server (attributed) in a MFC-application with several threads. In the main thread of the MFC-application I use smartpointers and CreateInstance to create an instance of the exe-server. By using CoInitializeEx(NULL, COINIT_MULTITHREADED) I get access to the server in every thread of my application. By using CoInitialize(NULL) just the main thread has access to the server, but that's clear. My Problem is, that if I use any ActiveX component in the application the threading model seems to be initialized automaticaly for single threading and calling CoInitialize is not possible anymore. Is there a solution for my problem ?

    P 1 Reply Last reply
    0
    • D Dietmar Goetz

      I want to use my exe-server (attributed) in a MFC-application with several threads. In the main thread of the MFC-application I use smartpointers and CreateInstance to create an instance of the exe-server. By using CoInitializeEx(NULL, COINIT_MULTITHREADED) I get access to the server in every thread of my application. By using CoInitialize(NULL) just the main thread has access to the server, but that's clear. My Problem is, that if I use any ActiveX component in the application the threading model seems to be initialized automaticaly for single threading and calling CoInitialize is not possible anymore. Is there a solution for my problem ?

      P Offline
      P Offline
      pba_
      wrote on last edited by
      #2

      The apartment is initialized for each thread once when you call CoInitInstance ( Ex). If you use COINIT_MULTITHREADED, you can pass around the interface ptr without any problems in any thread marked as MTA. Between threads with different apartments you must marshall the interface ( you can use CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream)

      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