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. COM
  4. Help!!!!! Need to do COM DLL with multiple objects

Help!!!!! Need to do COM DLL with multiple objects

Scheduled Pinned Locked Moved COM
comalgorithmshelpquestion
6 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.
  • L Offline
    L Offline
    Logan from Singapore
    wrote on last edited by
    #1

    Hi, I am trying to a COM DLL with multiple objects but I only want to expose one interface to the user. I would like to achieve something similar to the ADODC object in VB. User can only declare a new instant of the ADODC but not the Recordset object in it. That is "Dim Ado as ADODC" is ok but "Dim rs as Recordset" is not ok. When user is writing a code in VB, I would like the user to be able to see the method and properties in the inner objects. Like the AddNew method or Field properties in recordset. That is Dim MyObj as MyProject--------------Dim ADO as ADODC MyObj = new MyProject---------------ADO = new ADO MyObj.Inner.InnerMethod/Prop--------------ADO.Recordset.Addnew While searching, I have come across terms like containment and Aggregation. I think containment is closer to what I am looking for but seems to be missing some finer details. From what I see Recordset "seems" to be a property field in ADODC. Am I heading in the right direction? Can someone help me with my "missing links" please....

    J 1 Reply Last reply
    0
    • L Logan from Singapore

      Hi, I am trying to a COM DLL with multiple objects but I only want to expose one interface to the user. I would like to achieve something similar to the ADODC object in VB. User can only declare a new instant of the ADODC but not the Recordset object in it. That is "Dim Ado as ADODC" is ok but "Dim rs as Recordset" is not ok. When user is writing a code in VB, I would like the user to be able to see the method and properties in the inner objects. Like the AddNew method or Field properties in recordset. That is Dim MyObj as MyProject--------------Dim ADO as ADODC MyObj = new MyProject---------------ADO = new ADO MyObj.Inner.InnerMethod/Prop--------------ADO.Recordset.Addnew While searching, I have come across terms like containment and Aggregation. I think containment is closer to what I am looking for but seems to be missing some finer details. From what I see Recordset "seems" to be a property field in ADODC. Am I heading in the right direction? Can someone help me with my "missing links" please....

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      Just implement the COM classes as you normally would, but without registering them. It requires you however to internally create the COM objects by other means than CoCreateInstance, but that's no biggie if you are using ATL. CComObject<T> can help you out there. You can new the objects as well, but IIRC, there are some obscure pitfalls with that method. -- An eye for an eye will only make the world blind.

      L 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        Just implement the COM classes as you normally would, but without registering them. It requires you however to internally create the COM objects by other means than CoCreateInstance, but that's no biggie if you are using ATL. CComObject<T> can help you out there. You can new the objects as well, but IIRC, there are some obscure pitfalls with that method. -- An eye for an eye will only make the world blind.

        L Offline
        L Offline
        Logan from Singapore
        wrote on last edited by
        #3

        Hi, Thanks for replying. I can see that you are pretty active in this topic. I am currently doing COM using ATL. So I may have problem implementing the COM class without registering them but that should not be too big a problem to solve. I picked up COM by using ATL directly, so I keep having this feeling that my fundamental is wrong and I am really struggling to understanding any code in genertated code at all. Do you know of any means where I can have a good read up on the internet. I know that the book Essential COM is highly recommended but before I get that I would like to read up more. Thanks again. Truth is not always popular, but it is always right.

        J 1 Reply Last reply
        0
        • L Logan from Singapore

          Hi, Thanks for replying. I can see that you are pretty active in this topic. I am currently doing COM using ATL. So I may have problem implementing the COM class without registering them but that should not be too big a problem to solve. I picked up COM by using ATL directly, so I keep having this feeling that my fundamental is wrong and I am really struggling to understanding any code in genertated code at all. Do you know of any means where I can have a good read up on the internet. I know that the book Essential COM is highly recommended but before I get that I would like to read up more. Thanks again. Truth is not always popular, but it is always right.

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          Sorry, I don't have any handy internet references available. I have not solved your problem before either. Well, I did it the lazy way by not including the coclasses in the IDL file. Had I not been on vacation right now, I could've experimented on your behalf to find a smart solution, because it is not unlikely that I will face this problem myself. One really bad "hack" I can think of right now, is to make the rgs-script associated with your COM class, an empty script. That should ensure that it is not registered at all. But please make sure that you use the CComObject<> template to instantiate the objects, otherwise the COM module's lock count will not be incremented (IIRC, that's the problem with just new-ing the objects). As I have not tried this hack at all, I can't say for certain that it will work. It could be the case that the rgs script parser doesn't allow empty script, in which case all you have to do is add some "dummy script" in your rgs file. Your mileage may vary. :) Good music: In my rosary[^]

          J L 2 Replies Last reply
          0
          • J Jorgen Sigvardsson

            Sorry, I don't have any handy internet references available. I have not solved your problem before either. Well, I did it the lazy way by not including the coclasses in the IDL file. Had I not been on vacation right now, I could've experimented on your behalf to find a smart solution, because it is not unlikely that I will face this problem myself. One really bad "hack" I can think of right now, is to make the rgs-script associated with your COM class, an empty script. That should ensure that it is not registered at all. But please make sure that you use the CComObject<> template to instantiate the objects, otherwise the COM module's lock count will not be incremented (IIRC, that's the problem with just new-ing the objects). As I have not tried this hack at all, I can't say for certain that it will work. It could be the case that the rgs script parser doesn't allow empty script, in which case all you have to do is add some "dummy script" in your rgs file. Your mileage may vary. :) Good music: In my rosary[^]

            J Offline
            J Offline
            Jorgen Sigvardsson
            wrote on last edited by
            #5

            Oh yeah.. in case you have not used the CComObject template, this is the way you use it:

            CComObject<CYourClass>* pObj;
            HRESULT hr = CComObject<CYourClass>::CreateInstance(&pObj);
            // handle error
            pObj->AddRef(); // Important, because CYourClass does *not* AddRef()

            CComObject will however stabilize the refcount during the construction phase (temporarily incrementing it). I think. :~ (It should!) Good music: In my rosary[^]

            1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              Sorry, I don't have any handy internet references available. I have not solved your problem before either. Well, I did it the lazy way by not including the coclasses in the IDL file. Had I not been on vacation right now, I could've experimented on your behalf to find a smart solution, because it is not unlikely that I will face this problem myself. One really bad "hack" I can think of right now, is to make the rgs-script associated with your COM class, an empty script. That should ensure that it is not registered at all. But please make sure that you use the CComObject<> template to instantiate the objects, otherwise the COM module's lock count will not be incremented (IIRC, that's the problem with just new-ing the objects). As I have not tried this hack at all, I can't say for certain that it will work. It could be the case that the rgs script parser doesn't allow empty script, in which case all you have to do is add some "dummy script" in your rgs file. Your mileage may vary. :) Good music: In my rosary[^]

              L Offline
              L Offline
              Logan from Singapore
              wrote on last edited by
              #6

              Thanks for the quick reply and thanks for taking the trouble to reply even when you are on vacation. One last question, how do you think the VB recordset example I use is implemented? Currently what I feel is that recordset is a get_property under ADODC and when this is call the pointer to the recordset object is in my COM is passed returned. But I found a project in code project that use a method to implement this, It does return the pointer of the inner object. Please dun take too much of your time on this, just give me your nbest guess. Thanks and enjoy your holiday.

              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