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. A strange issue about custom interface

A strange issue about custom interface

Scheduled Pinned Locked Moved 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.
  • M Offline
    M Offline
    maya
    wrote on last edited by
    #1

    DLL-based Component CA is developed with ATL Object wizard. Its features including: 1. single-threaded 2. custom interface 3. no aggregation support CA has only one interface named IA which has a method GetData: STDMETHOD(Receive)(/*[out]*/ long* pDataLength, /*[out, size_is(*pDataLength)]*/ unsigned char** ppData); A confusing fact is that: When I use CA in a normal MFC EXE, it works well. Then I use CA in an ATL-based EXE. In that EXE I have another Componet say CB. CB creates a thread say WorkingThread(). In WorkingThread(), I call CreateInsantance() to create CA: IA* pIA = NULL; RESULT hr = CoCreateInstance(CLSID_A, NULL, CLSCTX_INPROC_SERVER, IID_IA, (void**)&pIA); It failed with a HRESULT indicating "The interface IA is not supported by CLSID_A". I have included A.h and two const definition of CLSID_A and IID_A in the ATL EXE's source, the same as I did in the normal MFC EXE. If CA is a dual interface, no such troubles. So I assume this is related to custom interface. But how to solve this problem?

    P 1 Reply Last reply
    0
    • M maya

      DLL-based Component CA is developed with ATL Object wizard. Its features including: 1. single-threaded 2. custom interface 3. no aggregation support CA has only one interface named IA which has a method GetData: STDMETHOD(Receive)(/*[out]*/ long* pDataLength, /*[out, size_is(*pDataLength)]*/ unsigned char** ppData); A confusing fact is that: When I use CA in a normal MFC EXE, it works well. Then I use CA in an ATL-based EXE. In that EXE I have another Componet say CB. CB creates a thread say WorkingThread(). In WorkingThread(), I call CreateInsantance() to create CA: IA* pIA = NULL; RESULT hr = CoCreateInstance(CLSID_A, NULL, CLSCTX_INPROC_SERVER, IID_IA, (void**)&pIA); It failed with a HRESULT indicating "The interface IA is not supported by CLSID_A". I have included A.h and two const definition of CLSID_A and IID_A in the ATL EXE's source, the same as I did in the normal MFC EXE. If CA is a dual interface, no such troubles. So I assume this is related to custom interface. But how to solve this problem?

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      You need to make sure that you call CoInitailize for each thread that will create COM objects. Basically this function inidicates to OLE which type of threading model that thread will use when it creates COM objects.


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      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