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. How to interface a COM class in a non-COM DLL

How to interface a COM class in a non-COM DLL

Scheduled Pinned Locked Moved COM
c++comsysadminhardwaretutorial
5 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
    morenz
    wrote on last edited by
    #1

    Hi folks! ;) I need to create a DCOM Server to manage multiple objects (hardware driver wrappers). I Created DCOM Server with object classes and methods declaration, but I wanted to envelope every object in a separate DLL, to be modular. (just to make things easier if I wanna change a board, i.e.) Now, I created a Win32 DLL (I do not need COM support, while I'm just implementing functions) but I need to get by parameter the effective class of my COM object. I tried that by including the object H file with class declaration, but it tells me that ATL_NO_VTABLE cannot be understood. What can I do? Did I reason well? Or I need a COM DLL anyway? Thanks a lot for now, Morenz

    G 1 Reply Last reply
    0
    • M morenz

      Hi folks! ;) I need to create a DCOM Server to manage multiple objects (hardware driver wrappers). I Created DCOM Server with object classes and methods declaration, but I wanted to envelope every object in a separate DLL, to be modular. (just to make things easier if I wanna change a board, i.e.) Now, I created a Win32 DLL (I do not need COM support, while I'm just implementing functions) but I need to get by parameter the effective class of my COM object. I tried that by including the object H file with class declaration, but it tells me that ATL_NO_VTABLE cannot be understood. What can I do? Did I reason well? Or I need a COM DLL anyway? Thanks a lot for now, Morenz

      G Offline
      G Offline
      geo_m
      wrote on last edited by
      #2

      Hi, I'm not sure what are you trying to achieve. I assume, that you have some DCOM object, exposing a set of functions, these being implemented in different .dlls, that can be dynamically loaded from your object. Problem is, that one of the parameters to these functions implemented in .dlls should be a pointer to the DCOM object that calls them. Is that right? I think you need to include the ATL headers into your dlls as well, to have defined the ATL macro ATL_NO_VTABLE. This will not change your .dlls to COM dlls (they will not require the registration) There's also another problem with the ALT objects. There's an interesting twist, because of IUnknown implementation. To keep it short, simply your ATL object is not really the object being constructed. If I assume your object name is CMyObject then the object constructed is in fact CComObject<CMyObject>. So to stay on the safe side, your parameter should not be only CMyClass&, but CComObject<CMyClass>& (or pointer if you prefer) Anyway, safest way would be to export some sort of interface from the DCOM object, that these dlls will use to communicate. Then you can take the declaration of the interface from the header file generated by MIDL and use it in the .dlls. (filename is usually projectname.h) Hope this helps

      M 1 Reply Last reply
      0
      • G geo_m

        Hi, I'm not sure what are you trying to achieve. I assume, that you have some DCOM object, exposing a set of functions, these being implemented in different .dlls, that can be dynamically loaded from your object. Problem is, that one of the parameters to these functions implemented in .dlls should be a pointer to the DCOM object that calls them. Is that right? I think you need to include the ATL headers into your dlls as well, to have defined the ATL macro ATL_NO_VTABLE. This will not change your .dlls to COM dlls (they will not require the registration) There's also another problem with the ALT objects. There's an interesting twist, because of IUnknown implementation. To keep it short, simply your ATL object is not really the object being constructed. If I assume your object name is CMyObject then the object constructed is in fact CComObject<CMyObject>. So to stay on the safe side, your parameter should not be only CMyClass&, but CComObject<CMyClass>& (or pointer if you prefer) Anyway, safest way would be to export some sort of interface from the DCOM object, that these dlls will use to communicate. Then you can take the declaration of the interface from the header file generated by MIDL and use it in the .dlls. (filename is usually projectname.h) Hope this helps

        M Offline
        M Offline
        morenz
        wrote on last edited by
        #3

        First of all thanx a lot, then... it's right what you say (about project architecure) but if I try to only #import my MIDL result (thats .TLB, not .h, I think) in my DLL, I have the error on ATL_NO_VTABLE. Do I have to #import all .idl files in my DLL? Or creating my CComObject& can work well? Thanx a lot again, I'm neither a COM nor a DLL expert (my last COM written was about in 1998... my last DLL in 1997...):laugh: Best regards, Morenz

        G 1 Reply Last reply
        0
        • M morenz

          First of all thanx a lot, then... it's right what you say (about project architecure) but if I try to only #import my MIDL result (thats .TLB, not .h, I think) in my DLL, I have the error on ATL_NO_VTABLE. Do I have to #import all .idl files in my DLL? Or creating my CComObject& can work well? Thanx a lot again, I'm neither a COM nor a DLL expert (my last COM written was about in 1998... my last DLL in 1997...):laugh: Best regards, Morenz

          G Offline
          G Offline
          geo_m
          wrote on last edited by
          #4

          hm, as I could understand the ATL_NO_VTABLE problem, when you're including the object.h file, the code generated with #import never contain the ATL macros. You probably forgot to remove the object.h include. I always used #import "blahblah.tlb" no_namespace named_guids for including COM objects to my projects. Problem is, that this doesn't import the object as-is from the C++ point of view. It defines all interfaces the object is derived from and all Guids required for the object - Guids of interfaces and of the object itself. If you look into your debug (or release) directory, you'll see object.tlh and object.tli (optional), that contains code generated by the #import. Well, when you have the interfaces imported, you can use one of them as a controlling interface. General interface is IUnknown. From this you can QueryInterface to get any other interface exported by the object. The CComObject thing is when you decide not to import interfaces, but the C++ object definition. The method I would choose depends on what you want to achieve, but generally I'd prefer to a) create a special interface for controlling the DCOM object, passed to the .dlls b) create a third c++ object, that is included in the DCOM as well as in the .dlls. It's purpose is only for exchanging the information - the DCOM object creates one instance and passes it to all calls to the .dlls. Or even considering the implementation to be in the C++ object and only calls from outside will be proxied through the DCOM object. Then the DCOM object will be only very thin wrapper - generally only thing it will does will be to create the third object (or derive from) and then simply proxy all calls from DCOM to the C++ object. I hope the explanation is clear, here's 7:00 morning ;-) The a) and b) are more or less equal, the a) is more COMish, while the b) is more C++ish.

          M 1 Reply Last reply
          0
          • G geo_m

            hm, as I could understand the ATL_NO_VTABLE problem, when you're including the object.h file, the code generated with #import never contain the ATL macros. You probably forgot to remove the object.h include. I always used #import "blahblah.tlb" no_namespace named_guids for including COM objects to my projects. Problem is, that this doesn't import the object as-is from the C++ point of view. It defines all interfaces the object is derived from and all Guids required for the object - Guids of interfaces and of the object itself. If you look into your debug (or release) directory, you'll see object.tlh and object.tli (optional), that contains code generated by the #import. Well, when you have the interfaces imported, you can use one of them as a controlling interface. General interface is IUnknown. From this you can QueryInterface to get any other interface exported by the object. The CComObject thing is when you decide not to import interfaces, but the C++ object definition. The method I would choose depends on what you want to achieve, but generally I'd prefer to a) create a special interface for controlling the DCOM object, passed to the .dlls b) create a third c++ object, that is included in the DCOM as well as in the .dlls. It's purpose is only for exchanging the information - the DCOM object creates one instance and passes it to all calls to the .dlls. Or even considering the implementation to be in the C++ object and only calls from outside will be proxied through the DCOM object. Then the DCOM object will be only very thin wrapper - generally only thing it will does will be to create the third object (or derive from) and then simply proxy all calls from DCOM to the C++ object. I hope the explanation is clear, here's 7:00 morning ;-) The a) and b) are more or less equal, the a) is more COMish, while the b) is more C++ish.

            M Offline
            M Offline
            morenz
            wrote on last edited by
            #5

            Yeah, I know what you meant, it was 7.00 here, too! ;) I read this only now, and tomorrow I will give it a shot. I 'll make you know. For now, many thanks.

            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