COM object (no type library) - how do I access the interface from VB.NET?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin Tucker

    COM object (no type library) - how do I access the interface from VB.NET?


    I have a COM object, which implements straightforward ly the IDataObject
    interface. It seems this isn't the same IDataObject interface we now have
    with .NET. Basically, the COM object implements low level interfaces. It
    does not have a type library. We use it freely with our unmanaged C++
    projects. What I would like to do is load or create one of these objects in
    VB.NET, but I cannot seem to do it.

    I've tried:

    Dim theObject As Object

    theObject = GetObject ( "c:\gas.tgw " ) * gas.tgw is a file-type we
    associated with the COM object

    but how do I get the IDataObject interface from theObject?

    Is it possible to use basic low-level COM interfaces with VB.NET?

    Any answers would be much appreciated.


  • David Browne

    #2
    Re: COM object (no type library) - how do I access the interface from VB.NET?


    "Robin Tucker" <r.tucker@therm oteknix.com> wrote in message
    news:bkctdd$p6b $1$8300dec7@new s.demon.co.uk.. .[color=blue]
    >
    > I have a COM object, which implements straightforward ly the IDataObject
    > interface. It seems this isn't the same IDataObject interface we now have
    > with .NET. Basically, the COM object implements low level interfaces. It
    > does not have a type library. We use it freely with our unmanaged C++
    > projects. What I would like to do is load or create one of these objects[/color]
    in[color=blue]
    > VB.NET, but I cannot seem to do it.
    >
    > I've tried:
    >
    > Dim theObject As Object
    >
    > theObject = GetObject ( "c:\gas.tgw " ) * gas.tgw is a file-type we
    > associated with the COM object
    >
    > but how do I get the IDataObject interface from theObject?
    >
    > Is it possible to use basic low-level COM interfaces with VB.NET?
    >[/color]

    Sure, you can use the COM interfaces but you need a type library. Then you
    need to generate an Interop Assembly.

    The type library may be embedded in the dll, or you could create it if you
    have the MSIL interface definitions.

    David


    Comment

    • Robin Tucker

      #3
      Re: COM object (no type library) - how do I access the interface from VB.NET?

      So I definately need a type library? There is no way we can generate one
      for this program - it implements IDataObject in COM but it isn't an
      automation object. I would have thought it would just be a case of finding
      the interface using "FindInterfaces ". But obviously not. In this case,
      VB.NET can't be properly supporting com I guess, if it only supports objects
      with type libs.

      "David Browne" <davidbaxterbro wne no potted meat@hotmail.co m> wrote in
      message news:O6MKoMhfDH A.2352@TK2MSFTN GP12.phx.gbl...[color=blue]
      >
      > "Robin Tucker" <r.tucker@therm oteknix.com> wrote in message
      > news:bkctdd$p6b $1$8300dec7@new s.demon.co.uk.. .[color=green]
      > >
      > > I have a COM object, which implements straightforward ly the IDataObject
      > > interface. It seems this isn't the same IDataObject interface we now[/color][/color]
      have[color=blue][color=green]
      > > with .NET. Basically, the COM object implements low level interfaces.[/color][/color]
      It[color=blue][color=green]
      > > does not have a type library. We use it freely with our unmanaged C++
      > > projects. What I would like to do is load or create one of these[/color][/color]
      objects[color=blue]
      > in[color=green]
      > > VB.NET, but I cannot seem to do it.
      > >
      > > I've tried:
      > >
      > > Dim theObject As Object
      > >
      > > theObject = GetObject ( "c:\gas.tgw " ) * gas.tgw is a file-type we
      > > associated with the COM object
      > >
      > > but how do I get the IDataObject interface from theObject?
      > >
      > > Is it possible to use basic low-level COM interfaces with VB.NET?
      > >[/color]
      >
      > Sure, you can use the COM interfaces but you need a type library. Then you
      > need to generate an Interop Assembly.
      >
      > The type library may be embedded in the dll, or you could create it if you
      > have the MSIL interface definitions.
      >
      > David
      >
      >[/color]


      Comment

      • David Browne

        #4
        Re: COM object (no type library) - how do I access the interface from VB.NET?


        "Robin Tucker" <r.tucker@therm oteknix.com> wrote in message
        news:bkcuej$qgm $1$8300dec7@new s.demon.co.uk.. .[color=blue]
        > So I definately need a type library? There is no way we can generate one
        > for this program - it implements IDataObject in COM but it isn't an
        > automation object. I would have thought it would just be a case of[/color]
        finding[color=blue]
        > the interface using "FindInterfaces ". But obviously not. In this case,
        > VB.NET can't be properly supporting com I guess, if it only supports[/color]
        objects[color=blue]
        > with type libs.[/color]

        How do the unmanaged C++ programs use this component?

        Do they have the interface definitions?
        Do they use IDispach?

        David



        Comment

        • Robin Tucker

          #5
          Re: COM object (no type library) - how do I access the interface from VB.NET?


          Something like this - we use CoGetObject - this is part of a method that
          gets data from the object and converts it into a DIB for rendering. As you
          can see, I may have my work cut-out in VB.NET! (but vb might get ditched if
          I cannot do things like this).


          // Connect to the object.
          IDataObjectPtr image;
          TryMethod(CoGet Object(display_ name, 0, IID_IDataObject , (void**)&image) );
          // First try to get a DIB.
          FORMATETC fe = { CF_DIB, 0, DVASPECT_CONTEN T, index, TYMED_HGLOBAL };
          if (SUCCEEDED(imag e->GetData(&fe, &sm)))
          {







          Comment

          • Robin Tucker

            #6
            Re: COM object (no type library) - how do I access the interface from VB.NET?

            We implement the following interfaces on the object:

            IClientSecurity
            IDataObject
            IDispatch
            IMarshal
            IMultiQI
            IOleContainer
            IOleInPlaceActi veObject
            IOleInPlaceObje ct
            IOleItemContain er
            IOleObject
            IOleWindow
            IParseDisplayNa me
            IPersist
            IPersistFile
            IPersistStorage
            IProxyManager
            IUnknown



            "David Browne" <davidbaxterbro wne no potted meat@hotmail.co m> wrote in
            message news:%230yZg4hf DHA.3616@TK2MSF TNGP11.phx.gbl. ..[color=blue]
            >
            > "Robin Tucker" <r.tucker@therm oteknix.com> wrote in message
            > news:bkcuej$qgm $1$8300dec7@new s.demon.co.uk.. .[color=green]
            > > So I definately need a type library? There is no way we can generate[/color][/color]
            one[color=blue][color=green]
            > > for this program - it implements IDataObject in COM but it isn't an
            > > automation object. I would have thought it would just be a case of[/color]
            > finding[color=green]
            > > the interface using "FindInterfaces ". But obviously not. In this case,
            > > VB.NET can't be properly supporting com I guess, if it only supports[/color]
            > objects[color=green]
            > > with type libs.[/color]
            >
            > How do the unmanaged C++ programs use this component?
            >
            > Do they have the interface definitions?
            > Do they use IDispach?
            >
            > David
            >
            >
            >[/color]


            Comment

            • Fergus Cooney

              #7
              Re: COM object (no type library) - how do I access the interface from VB.NET?

              Hi Robin,

              Have you tried hauling in your component by adding a Reference to your
              project? When I tried that (a long time ago) it said something like "There's
              no blah, blah, would you like me to create an Interop wrapper?". Yes please
              and off you go. It may not be clever enough to map all your functions but then
              again, it may.

              Regards,
              Fergus
              MVP [Windows Start button, Shutdown dialogue]


              Comment

              • Robin Tucker

                #8
                Re: COM object (no type library) - how do I access the interface from VB.NET?

                No chance! It says it isn't a valid COM component or assembly, which, in a
                sense, I guess is true. The component won't show up in the COM tab because
                it doesn't have a typelib and it isn't an automation object. My guess is it
                just isn't possible and I will either have to create a C++ source file that
                will do it for me and somehow links into VB.NET or I will ditch VB.NET and
                go back to plain old C++, ATL etc.



                "Fergus Cooney" <filter-1@tesco.net> wrote in message
                news:Orpy$ZifDH A.3248@tk2msftn gp13.phx.gbl...[color=blue]
                > Hi Robin,
                >
                > Have you tried hauling in your component by adding a Reference to your
                > project? When I tried that (a long time ago) it said something like[/color]
                "There's[color=blue]
                > no blah, blah, would you like me to create an Interop wrapper?". Yes[/color]
                please[color=blue]
                > and off you go. It may not be clever enough to map all your functions but[/color]
                then[color=blue]
                > again, it may.
                >
                > Regards,
                > Fergus
                > MVP [Windows Start button, Shutdown dialogue]
                >
                >[/color]


                Comment

                • Fergus Cooney

                  #9
                  Re: COM object (no type library) - how do I access the interface from VB.NET?

                  Hi Robin,

                  Shame about that. I'd go the C++ wrapper and then get a .NET wrapper. And
                  then you can write some wrapper classes around it in VB.NET just so it feels
                  really warm and cosy. :-)

                  Go back?? You can't go back. Or maybe I'm just biased.

                  Best wishes,
                  Fergus
                  MVP [Windows Start button, Shutdown dialogue]


                  Comment

                  • Robin Tucker

                    #10
                    Re: COM object (no type library) - how do I access the interface from VB.NET?

                    What I don't understand about this situation is the files will happily embed
                    in Word documents (Insert->Object) - so I must be doing something wrong!

                    I don't want to go back to C++ - luckily I'm just experimenting with VB.NET
                    at the start of a project which, after much deliberation, we decided would
                    be best written in VB.NET. Of course, provided our existing COM components
                    were compatible. Designing a nice looking UI is a pain in the ass with ATL.
                    I am going to jump out of the office window if I have to do that.

                    "Fergus Cooney" <filter-1@tesco.net> wrote in message
                    news:udMuArifDH A.2356@TK2MSFTN GP12.phx.gbl...[color=blue]
                    > Hi Robin,
                    >
                    > Shame about that. I'd go the C++ wrapper and then get a .NET wrapper.[/color]
                    And[color=blue]
                    > then you can write some wrapper classes around it in VB.NET just so it[/color]
                    feels[color=blue]
                    > really warm and cosy. :-)
                    >
                    > Go back?? You can't go back. Or maybe I'm just biased.
                    >
                    > Best wishes,
                    > Fergus
                    > MVP [Windows Start button, Shutdown dialogue]
                    >
                    >[/color]


                    Comment

                    • David Browne

                      #11
                      Re: COM object (no type library) - how do I access the interface from VB.NET?


                      "Robin Tucker" <r.tucker@therm oteknix.com> wrote in message
                      news:bkd3f0$3vu $1$8300dec7@new s.demon.co.uk.. .[color=blue]
                      >
                      > Something like this - we use CoGetObject - this is part of a method that
                      > gets data from the object and converts it into a DIB for rendering. As[/color]
                      you[color=blue]
                      > can see, I may have my work cut-out in VB.NET! (but vb might get ditched[/color]
                      if[color=blue]
                      > I cannot do things like this).
                      >
                      >
                      > // Connect to the object.
                      > IDataObjectPtr image;
                      > TryMethod(CoGet Object(display_ name, 0, IID_IDataObject , (void**)&image) );
                      > // First try to get a DIB.
                      > FORMATETC fe = { CF_DIB, 0, DVASPECT_CONTEN T, index, TYMED_HGLOBAL };
                      > if (SUCCEEDED(imag e->GetData(&fe, &sm)))
                      > {
                      >[/color]
                      Great!!

                      You should have what you need.

                      In your C++ program source folder you should have either the .tlb or an .idl
                      file.

                      If you have an .idl file, just run midl.exe on it and it will output the
                      type library (as well as some .c stubs which you don't need). Then in
                      dotnet just add a reference to the .tlb file.

                      David



                      Comment

                      • Matt Evans [MSFT]

                        #12
                        Re: COM object (no type library) - how do I access the interface from VB.NET?

                        A few things to try:

                        midl
                        tlbimp
                        tlbexp (i think)

                        failing that, a fantastic way to make managed wrappers for non managed code
                        (COM or otherwise) is by using Managed C++
                        If you're proficient with C++ managed C++ will let you perfectly tune how
                        you expose your existing C/C++ code to the managed world. You can write
                        the remainder of your app in VB.NET...




                        --------------------[color=blue]
                        >From: "Robin Tucker" <r.tucker@therm oteknix.com>
                        >Newsgroups: microsoft.publi c.dotnet.langua ges.vb
                        >Subject: Re: COM object (no type library) - how do I access the interface[/color]
                        from VB.NET?[color=blue]
                        >Date: Thu, 18 Sep 2003 22:10:13 +0100
                        >Lines: 29
                        >Message-ID: <bkd6sd$kdq$1$8 302bc10@news.de mon.co.uk>
                        >References: <bkctdd$p6b$1$8 300dec7@news.de mon.co.uk>[/color]
                        <O6MKoMhfDHA.23 52@TK2MSFTNGP12 .phx.gbl>
                        <bkcuej$qgm$1$8 300dec7@news.de mon.co.uk>
                        <Orpy$ZifDHA.32 48@tk2msftngp13 .phx.gbl>[color=blue]
                        >NNTP-Posting-Host: 80.176.255.158
                        >X-Trace: news.demon.co.u k 1063919309 20922 80.176.255.158 (18 Sep 2003[/color]
                        21:08:29 GMT)[color=blue]
                        >X-Complaints-To: abuse@demon.net
                        >NNTP-Posting-Date: Thu, 18 Sep 2003 21:08:29 +0000 (UTC)
                        >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
                        >X-Priority: 3
                        >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
                        >X-MSMail-Priority: Normal
                        >Path:[/color]
                        cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
                        e.de!kibo.news. demon.net!news. demon.co.uk!dem on!not-for-mail[color=blue]
                        >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:139063
                        >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
                        >
                        >No chance! It says it isn't a valid COM component or assembly, which, in a
                        >sense, I guess is true. The component won't show up in the COM tab[/color]
                        because[color=blue]
                        >it doesn't have a typelib and it isn't an automation object. My guess is[/color]
                        it[color=blue]
                        >just isn't possible and I will either have to create a C++ source file that
                        >will do it for me and somehow links into VB.NET or I will ditch VB.NET and
                        >go back to plain old C++, ATL etc.
                        >
                        >
                        >
                        >"Fergus Cooney" <filter-1@tesco.net> wrote in message
                        >news:Orpy$ZifD HA.3248@tk2msft ngp13.phx.gbl.. .[color=green]
                        >> Hi Robin,
                        >>
                        >> Have you tried hauling in your component by adding a Reference to[/color][/color]
                        your[color=blue][color=green]
                        >> project? When I tried that (a long time ago) it said something like[/color]
                        >"There's[color=green]
                        >> no blah, blah, would you like me to create an Interop wrapper?". Yes[/color]
                        >please[color=green]
                        >> and off you go. It may not be clever enough to map all your functions but[/color]
                        >then[color=green]
                        >> again, it may.
                        >>
                        >> Regards,
                        >> Fergus
                        >> MVP [Windows Start button, Shutdown dialogue]
                        >>
                        >>[/color]
                        >
                        >
                        >[/color]

                        Matt Evans
                        --

                        This posting is provided "AS IS" with no warranties, and confers no rights.
                        Use of included script samples are subject to the terms specified at
                        Use these online forms to report copyright and trademark infringement to Microsoft Legal. Infringement notices must comply with the Digital Millennium Copyright Act.


                        Note: For the benefit of the community-at-large, all responses to this
                        message are best directed to the newsgroup/thread from which they
                        originated.

                        Comment

                        Working...