DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: .Net to COM basics question

  1. #1
    Frank Hofstaedter Guest

    .Net to COM basics question

    Hi -

    I'm trying to understand some fundamental .Net/COM interoperability issues
    and would appreciate anyone shedding some light.

    What is necessary to early bind to COM classes? Is it sufficient to use the
    references dialog in VS.Net to point to the COM typelib like we do in VB6?
    Does an assembly have to be generated off of the existing typelib to
    successfully early bind?

    What is necessary to late bind to a COM class? Is there the equivalent of
    CreateObject or does one accomplish this by wading through the
    System.Reflection set of classes?

    Finally, does Microsoft maintain a publically accessible list of known
    "issues" with the Beta so I don't bang my head against the wall trying to
    figure what's wrong with things already known to be bugs?





  2. #2
    Patrick Steele Guest

    Re: .Net to COM basics question

    In article <3a8412a9$1@news.devx.com>, fhofstaedter@hotmail.com says...
    > Hi -
    >
    > I'm trying to understand some fundamental .Net/COM interoperability issues
    > and would appreciate anyone shedding some light.
    >
    > What is necessary to early bind to COM classes? Is it sufficient to use the
    > references dialog in VS.Net to point to the COM typelib like we do in VB6?
    > Does an assembly have to be generated off of the existing typelib to
    > successfully early bind?


    Use the tlbimp utility to create a wrapper around your COM objects. This
    wrapper is a regular .NET assembly that you add as a reference. Use the
    "Imports" statement (or just fully qualify the object name) when creating
    a variable to reference the object.

    > What is necessary to late bind to a COM class? Is there the equivalent of
    > CreateObject or does one accomplish this by wading through the
    > System.Reflection set of classes?


    Basically, the same thing, except the variable type should be declared
    "As Object".

    > Finally, does Microsoft maintain a publically accessible list of known
    > "issues" with the Beta so I don't bang my head against the wall trying to
    > figure what's wrong with things already known to be bugs?


    Not that I know. This group is a good place to bounce ideas off people.
    Also, the DOTNET list at DevelopMentor is a good one:

    http://discuss.develop.com

    --
    Patrick Steele
    (psteele@ipdsolution.com)
    Lead Software Architect
    Image Process Design

  3. #3
    Frank Hofstaedter Guest

    Re: .Net to COM basics question

    Thanks for the info Patrick - that helps clarify things. Unfortunately, I
    still can't get my test to work. I am replicating a VB6 utility I wrote in
    VB.net that utilized SQLDMO. The app simply terminates upon instantiation
    of the SQLServer object - no exceptions, no nuthin', just terminates the
    execution of the app and returns to design mode. I thought it might have
    something to do with referencing it as a dotNet assembly vs. referencing it
    as a COM object. Both ways establish references and show up in the object
    browser just fine and both ways die at the same spot. Perhaps the Beta just
    isn't ready to talk to SQLDMO yet! Thanks.



  4. #4
    Patrick Steele Guest

    Re: .Net to COM basics question

    In article <3a841df8$1@news.devx.com>, fhofstaedter@hotmail.com says...
    > Thanks for the info Patrick - that helps clarify things. Unfortunately, I
    > still can't get my test to work. I am replicating a VB6 utility I wrote in
    > VB.net that utilized SQLDMO. The app simply terminates upon instantiation
    > of the SQLServer object - no exceptions, no nuthin', just terminates the
    > execution of the app and returns to design mode. I thought it might have
    > something to do with referencing it as a dotNet assembly vs. referencing it
    > as a COM object. Both ways establish references and show up in the object
    > browser just fine and both ways die at the same spot. Perhaps the Beta just
    > isn't ready to talk to SQLDMO yet! Thanks.


    Make sure you define the object type properly. Some objects need to be
    defined as the interface to a class -- not the class itself. See:

    http://discuss.develop.com/archives/...DOTNET&P=R4065

    For more information.

    --
    Patrick Steele
    (psteele@ipdsolution.com)
    Lead Software Architect
    Image Process Design

  5. #5
    Frank Hofstaedter Guest

    Re: .Net to COM basics question

    Apparently not only did I have to define the variable as the interface to
    the class, but I had to have the correct class instantiated as well. This
    is the code that now works:
    Dim objSQLServer As SQLDMO._SQLServer


    objSQLServer = New SQLDMO.__SQLServer()

    With objSQLServer

    ..Connect("00LP154")

    End With

    objSQLServer = Nothing


    End Sub

    Thanks a lot! At the risk of revealing even more ignorance, other questions
    arise: Where the %^&#@ did the __SQLServer class come from? VB6 doesn't
    see it and is perfectly happy using the SQLServer class. Is this some kind
    of on-the fly assembly generation creating new class definitions in vs.net?
    And regarding your statement: "Some objects need to be defined as the
    interface to a class -- not the class itself" If an interface and base
    class expose the same method signatures, how/when/why would I know that I
    have to define to the interface rather than the class? Thanks!

    "Patrick Steele" <psteele@ipdsolution.com_> wrote in message
    news:MPG.14ede9c42289a9e89896ab@news.devx.com...
    >
    > Make sure you define the object type properly. Some objects need to be
    > defined as the interface to a class -- not the class itself. See:
    >
    > http://discuss.develop.com/archives/...DOTNET&P=R4065
    >
    > For more information.
    >
    > --
    > Patrick Steele
    > (psteele@ipdsolution.com)
    > Lead Software Architect
    > Image Process Design




  6. #6
    Patrick Steele Guest

    Re: .Net to COM basics question

    In article <3a842e71$1@news.devx.com>, fhofstaedter@hotmail.com says...
    >
    > Thanks a lot! At the risk of revealing even more ignorance, other questions
    > arise: Where the %^&#@ did the __SQLServer class come from? VB6 doesn't
    > see it and is perfectly happy using the SQLServer class. Is this some kind
    > of on-the fly assembly generation creating new class definitions in vs.net?


    To be honest, I'm not entirely sure. It may actually be that VB6 used
    the __SQLServer class in the background -- it just hid you from the
    details. Again -- this is a guess.

    > And regarding your statement: "Some objects need to be defined as the
    > interface to a class -- not the class itself" If an interface and base
    > class expose the same method signatures, how/when/why would I know that I
    > have to define to the interface rather than the class? Thanks!


    Check the signature of the method you're calling. I was doing some work
    with importing the Rational Rose COM API and noticed places where
    functions actually returned "IClasses" instead of "Classes" -- which I
    used to use in VB6. The object browser showed the function as returning
    an "IClasses" and not a "Classes" object.

    Another guess -- it's more stuff VB6 did in the background...

    --
    Patrick Steele
    (psteele@ipdsolution.com)
    Lead Software Architect
    Image Process Design

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center