Calling VB.Net classes from VB6

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

    #1

    Calling VB.Net classes from VB6

    I am trying to test out the ability of VB6 (VBA access) to instanciate a
    VB.net Object and call its methods. I came accross the following article in
    my vs2005 help search:
    ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEV.v10.e n/dndotnet/html/callnetfrcom.ht m
    Problem is it doesn't work!
    Can someone point me a "How-to" for exposing .net classes to com (VS2005)
    that actually works?

    --
    Terry
  • Walter Wang [MSFT]

    #2
    RE: Calling VB.Net classes from VB6

    Hi Terry,

    Thank you posting!

    This is a quick note to let you know that I am performing research on this
    issue and will get back to you as soon as possible. I appreciate your
    patience.

    Regards,
    Walter Wang
    Microsoft Online Community Support

    =============== =============== =============== =====
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    =============== =============== =============== =====

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Comment

    • tlkerns

      #3
      RE: Calling VB.Net classes from VB6

      Have you seen this article:

      http://msdn.microsoft.com/msdnmag/is...p/default.aspx

      Tony

      "Walter Wang [MSFT]" wrote:
      [color=blue]
      > Hi Terry,
      >
      > Thank you posting!
      >
      > This is a quick note to let you know that I am performing research on this
      > issue and will get back to you as soon as possible. I appreciate your
      > patience.
      >
      > Regards,
      > Walter Wang
      > Microsoft Online Community Support
      >
      > =============== =============== =============== =====
      > When responding to posts, please "Reply to Group" via your newsreader so
      > that others may learn and benefit from your issue.
      > =============== =============== =============== =====
      >
      > This posting is provided "AS IS" with no warranties, and confers no rights.
      >
      >[/color]

      Comment

      • Terry

        #4
        RE: Calling VB.Net classes from VB6

        Hi Walter,
        It appears that the problem is that the article was written for an
        earlier version of .Net. Is there an equivalent 'how to' for VS 2005? I
        want the .Net class that I am creating to be usable by both VB6/VBA and .Net.
        --
        Terry


        "Walter Wang [MSFT]" wrote:
        [color=blue]
        > Hi Terry,
        >
        > Thank you posting!
        >
        > This is a quick note to let you know that I am performing research on this
        > issue and will get back to you as soon as possible. I appreciate your
        > patience.
        >
        > Regards,
        > Walter Wang
        > Microsoft Online Community Support
        >
        > =============== =============== =============== =====
        > When responding to posts, please "Reply to Group" via your newsreader so
        > that others may learn and benefit from your issue.
        > =============== =============== =============== =====
        >
        > This posting is provided "AS IS" with no warranties, and confers no rights.
        >
        >[/color]

        Comment

        • Terry

          #5
          RE: Calling VB.Net classes from VB6

          Hi Tony,
          Thanks! One question though. If I go this approach, will the object be
          callable from .Net as a '.Net class', or will I then have to treat it as a
          'real' com object and wrap it again?
          --
          Terry


          "tlkerns" wrote:
          [color=blue]
          > Have you seen this article:
          >
          > http://msdn.microsoft.com/msdnmag/is...p/default.aspx
          >
          > Tony
          >
          > "Walter Wang [MSFT]" wrote:
          >[color=green]
          > > Hi Terry,
          > >
          > > Thank you posting!
          > >
          > > This is a quick note to let you know that I am performing research on this
          > > issue and will get back to you as soon as possible. I appreciate your
          > > patience.
          > >
          > > Regards,
          > > Walter Wang
          > > Microsoft Online Community Support
          > >
          > > =============== =============== =============== =====
          > > When responding to posts, please "Reply to Group" via your newsreader so
          > > that others may learn and benefit from your issue.
          > > =============== =============== =============== =====
          > >
          > > This posting is provided "AS IS" with no warranties, and confers no rights.
          > >
          > >[/color][/color]

          Comment

          • rmacias

            #6
            RE: Calling VB.Net classes from VB6

            Although the article tells you how to create a COM Callable Wrapper, it fails
            to mention what exactly is going on.

            When you build your .NET dll, the compiler is actually creating two files.
            The first file is your .NET *.dll file and the other is a Type Library *.tlb
            for your .NET dll. If your dll is named "MyLibrary.dll" , the compiler will
            create a file called "MyLibrary.tlb" .

            Your VB6 program will reference MyLibrary.tlb (which is a COM wrapper for
            MyLibrary.dll). VB6 will execute MyLibrary.dll through MyLibrary.tlb.

            If you have other .NET clients that need to call MyLibrary.dll, just
            reference that directly.

            So to answer your question, the same class can be called as a .NET class as
            well.

            "Terry" wrote:
            [color=blue]
            > Hi Tony,
            > Thanks! One question though. If I go this approach, will the object be
            > callable from .Net as a '.Net class', or will I then have to treat it as a
            > 'real' com object and wrap it again?
            > --
            > Terry
            >
            >
            > "tlkerns" wrote:
            >[color=green]
            > > Have you seen this article:
            > >
            > > http://msdn.microsoft.com/msdnmag/is...p/default.aspx
            > >
            > > Tony
            > >
            > > "Walter Wang [MSFT]" wrote:
            > >[color=darkred]
            > > > Hi Terry,
            > > >
            > > > Thank you posting!
            > > >
            > > > This is a quick note to let you know that I am performing research on this
            > > > issue and will get back to you as soon as possible. I appreciate your
            > > > patience.
            > > >
            > > > Regards,
            > > > Walter Wang
            > > > Microsoft Online Community Support
            > > >
            > > > =============== =============== =============== =====
            > > > When responding to posts, please "Reply to Group" via your newsreader so
            > > > that others may learn and benefit from your issue.
            > > > =============== =============== =============== =====
            > > >
            > > > This posting is provided "AS IS" with no warranties, and confers no rights.
            > > >
            > > >[/color][/color][/color]

            Comment

            • Terry

              #7
              RE: Calling VB.Net classes from VB6

              Hi,
              Thanks for the explanation. I am still haveing a problem though. I
              posted another question on 6-2, about exposing a .Net assembly to both VB6
              and .Net. The gist of that posting is that after adding it to the GAC, it
              does not appear on the .Net tab of referencable assemblies. Which seems to
              imply that you have to have a local copy. Any ideas?
              --
              Terry


              "rmacias" wrote:
              [color=blue]
              > Although the article tells you how to create a COM Callable Wrapper, it fails
              > to mention what exactly is going on.
              >
              > When you build your .NET dll, the compiler is actually creating two files.
              > The first file is your .NET *.dll file and the other is a Type Library *.tlb
              > for your .NET dll. If your dll is named "MyLibrary.dll" , the compiler will
              > create a file called "MyLibrary.tlb" .
              >
              > Your VB6 program will reference MyLibrary.tlb (which is a COM wrapper for
              > MyLibrary.dll). VB6 will execute MyLibrary.dll through MyLibrary.tlb.
              >
              > If you have other .NET clients that need to call MyLibrary.dll, just
              > reference that directly.
              >
              > So to answer your question, the same class can be called as a .NET class as
              > well.
              >
              > "Terry" wrote:
              >[color=green]
              > > Hi Tony,
              > > Thanks! One question though. If I go this approach, will the object be
              > > callable from .Net as a '.Net class', or will I then have to treat it as a
              > > 'real' com object and wrap it again?
              > > --
              > > Terry
              > >
              > >
              > > "tlkerns" wrote:
              > >[color=darkred]
              > > > Have you seen this article:
              > > >
              > > > http://msdn.microsoft.com/msdnmag/is...p/default.aspx
              > > >
              > > > Tony
              > > >
              > > > "Walter Wang [MSFT]" wrote:
              > > >
              > > > > Hi Terry,
              > > > >
              > > > > Thank you posting!
              > > > >
              > > > > This is a quick note to let you know that I am performing research on this
              > > > > issue and will get back to you as soon as possible. I appreciate your
              > > > > patience.
              > > > >
              > > > > Regards,
              > > > > Walter Wang
              > > > > Microsoft Online Community Support
              > > > >
              > > > > =============== =============== =============== =====
              > > > > When responding to posts, please "Reply to Group" via your newsreader so
              > > > > that others may learn and benefit from your issue.
              > > > > =============== =============== =============== =====
              > > > >
              > > > > This posting is provided "AS IS" with no warranties, and confers no rights.
              > > > >
              > > > >[/color][/color][/color]

              Comment

              • Walter Wang [MSFT]

                #8
                RE: Calling VB.Net classes from VB6


                Thanks you rmacias for your contribution.

                Hi Terry,

                Yes, the article you're refering to in the first post is now obsolete for
                Visual Studio 2005. We can now use a more simpler way to do this. We use
                ComClassAttribu te to simply the process of exposing COM components from
                Visual Basic 2005. COM objects are very different from .NET framework
                assemblies; without the ComClassAttribu te, you need to follow a number of
                steps to generate a COM object from Visual Basic 2005. For classes marked
                with ComClassAttribu te, the compiler performs many of these steps
                automatically.

                #ComClassAttrib ute Class
                http://msdn2.microsoft.com/en-us/lib....comclassattri
                bute.aspx


                Although you can also expose a class created with Visual Basic as a COM
                object for unmanaged code to use, it is not a true COM object. When a COM
                client calls a .NET object, the common language runtime creates the managed
                object and a COM Callable Wrapper (CCW) for the object. Unable to reference
                a .NET object directly, COM clients use the CCW as a proxy for the managed
                object. COM callable wrappers are invisible to other classes running within
                the .NET Framework.


                #COM Callable Wrapper
                http://msdn2.microsoft.com/en-us/library/f07c8z1c.aspx

                From above article, you will see that other .NET objects will still using
                the same way to call the .NET object which is exposed as COM component.

                You may also take a look at following resource center about VB Fusion:

                #Visual Basic 6.0 Resource Center: VB Fusion
                http://msdn.microsoft.com/vbrun/vbfusion/

                As for your last post about that not seeing the assembly in Visual Studio
                IDE, I will reply in the separate thread you just posted.

                Hope this helps. If anything is unclear, please feel free to post here.


                Regards,
                Walter Wang
                Microsoft Online Community Support

                =============== =============== =============== =====
                When responding to posts, please "Reply to Group" via your newsreader so
                that others may learn and benefit from your issue.
                =============== =============== =============== =====

                This posting is provided "AS IS" with no warranties, and confers no rights.

                Comment

                • Terry

                  #9
                  RE: Calling VB.Net classes from VB6

                  Hi and thanks for the help.
                  Ok, I think I am getting the picture. Unlike VB6, when I register a dll
                  and it is placed on the 'list of available references' to another VB6
                  project, running the gactil to 'register' the .Net assembly with the GAC does
                  NOT put it on the list of .Net assemblies available for reference. The fact
                  that I 'browse' to it at 'development' time, has nothing to do with how the
                  CLR finds it after 'deployment'.
                  If I want the assembly to appear on the .Net tab, I can either put it in
                  the public assemblies folder or add an entry to registry to add the path.
                  At deployment time, I will run both the gactil and regasm for each of the
                  com callable assemblies.
                  Thanks for the help!
                  --
                  Terry


                  "Walter Wang [MSFT]" wrote:
                  [color=blue]
                  >
                  > Thanks you rmacias for your contribution.
                  >
                  > Hi Terry,
                  >
                  > Yes, the article you're refering to in the first post is now obsolete for
                  > Visual Studio 2005. We can now use a more simpler way to do this. We use
                  > ComClassAttribu te to simply the process of exposing COM components from
                  > Visual Basic 2005. COM objects are very different from .NET framework
                  > assemblies; without the ComClassAttribu te, you need to follow a number of
                  > steps to generate a COM object from Visual Basic 2005. For classes marked
                  > with ComClassAttribu te, the compiler performs many of these steps
                  > automatically.
                  >
                  > #ComClassAttrib ute Class
                  > http://msdn2.microsoft.com/en-us/lib....comclassattri
                  > bute.aspx
                  >
                  >
                  > Although you can also expose a class created with Visual Basic as a COM
                  > object for unmanaged code to use, it is not a true COM object. When a COM
                  > client calls a .NET object, the common language runtime creates the managed
                  > object and a COM Callable Wrapper (CCW) for the object. Unable to reference
                  > a .NET object directly, COM clients use the CCW as a proxy for the managed
                  > object. COM callable wrappers are invisible to other classes running within
                  > the .NET Framework.
                  >
                  >
                  > #COM Callable Wrapper
                  > http://msdn2.microsoft.com/en-us/library/f07c8z1c.aspx
                  >
                  > From above article, you will see that other .NET objects will still using
                  > the same way to call the .NET object which is exposed as COM component.
                  >
                  > You may also take a look at following resource center about VB Fusion:
                  >
                  > #Visual Basic 6.0 Resource Center: VB Fusion
                  > http://msdn.microsoft.com/vbrun/vbfusion/
                  >
                  > As for your last post about that not seeing the assembly in Visual Studio
                  > IDE, I will reply in the separate thread you just posted.
                  >
                  > Hope this helps. If anything is unclear, please feel free to post here.
                  >
                  >
                  > Regards,
                  > Walter Wang
                  > Microsoft Online Community Support
                  >
                  > =============== =============== =============== =====
                  > When responding to posts, please "Reply to Group" via your newsreader so
                  > that others may learn and benefit from your issue.
                  > =============== =============== =============== =====
                  >
                  > This posting is provided "AS IS" with no warranties, and confers no rights.
                  >
                  >[/color]

                  Comment

                  • Walter Wang [MSFT]

                    #10
                    RE: Calling VB.Net classes from VB6

                    Hi Terry,

                    Thank you for your update. Please feel free to post here if anything is
                    unclear.

                    Have a nice day!

                    Regards,
                    Walter Wang
                    Microsoft Online Community Support

                    =============== =============== =============== =====
                    When responding to posts, please "Reply to Group" via your newsreader so
                    that others may learn and benefit from your issue.
                    =============== =============== =============== =====

                    This posting is provided "AS IS" with no warranties, and confers no rights.

                    Comment

                    Working...