By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Calling VB.Net classes from VB6

P: n/a
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.en/dndotnet/html/callnetfrcom.htm
Problem is it doesn't work!
Can someone point me a "How-to" for exposing .net classes to com (VS2005)
that actually works?

--
Terry
Jun 2 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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.

Jun 2 '06 #2

P: n/a
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.

Jun 2 '06 #3

P: n/a
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:
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.

Jun 2 '06 #4

P: n/a
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:
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.

Jun 2 '06 #5

P: n/a
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:
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:
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.

Jun 4 '06 #6

P: n/a
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:
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:
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:
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.
>
>

Jun 4 '06 #7

P: n/a

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
ComClassAttribute to simply the process of exposing COM components from
Visual Basic 2005. COM objects are very different from .NET framework
assemblies; without the ComClassAttribute, you need to follow a number of
steps to generate a COM object from Visual Basic 2005. For classes marked
with ComClassAttribute, the compiler performs many of these steps
automatically.

#ComClassAttribute 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.

Jun 5 '06 #8

P: n/a
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:

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
ComClassAttribute to simply the process of exposing COM components from
Visual Basic 2005. COM objects are very different from .NET framework
assemblies; without the ComClassAttribute, you need to follow a number of
steps to generate a COM object from Visual Basic 2005. For classes marked
with ComClassAttribute, the compiler performs many of these steps
automatically.

#ComClassAttribute 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.

Jun 6 '06 #9

P: n/a
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.

Jun 7 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.