|
-
Nov 5th, 2001, 12:17 PM
#1
Thread Starter
Junior Member
Programming VB.Net dll's for use with COM?
Hi everyone. I am wanting to do all new new development in VB.Net but im confused on making your vb.net dll's compatible with COM even after reading several articles from MSDN. I read one specific article were they talk about ClassInterfaceAttribute and how you can use it to tell VB.Net what type of COM interface you want to build. I know that COM by default uses dispatch only which i think is the same as ClassInterfaceType.AutoDual. When use specify ClassInterfaceType.None it appears that this is used by COM for late bound clients. They talked something about cache dispid's but i really didn't understand what they were talking about since if your doing
dim i as variant
set i = createobject("Mydll.CreateInstance") and you replace the dll/type library with a new version i don't see how that could cause a problem if your cache or not cache dispid's. They also talk about ClassInterfaceType.AutoDispatch which sounds like what i want to do but they recommend against it. I can't understand why. I want my vb.net object to act like any ordinary COM VB object in that i can early bind or late bind to them. Any help would be highly appreciated.
thanks in advance
ncage
-
Nov 6th, 2001, 09:19 AM
#2
There is, as you've probably noticed, a number of approaches that are presented in the documentation as optional.
The following is a short description, or presentation, that showing you the correct way to expose VB.Net objects but it's limited to that without all the optional approaches.
The easiest way is to simply check the "Register for COM interop" checkbox on the project setting dialog box.
However, as you have noticed, doing so will only support late binding.
VB.Net will not automatically create the private dual interface fir a class that allows both early and late binding, you'll just have to do that yourself.
So the correct way is to write the interface and explicitly define it in the Class.
VB Code:
Imports System.Runtime.InteropServices
Public Interface _CallableFromCOM
Function SomeMethod(ByVal i As Integer) As Integer
'... all other methods
End Interface
Public Class CallableFromCOM
Implements _CallableFromCOM 'implement the interface
Public Function SomeMethod(ByVal i As Integer) As Integer Implements _CallableFromCOM.SomeMethod
Return i
End Function
End Class
Now, you have to instruct the VB.Net compiler that COM objects can use this component.
This is accomplished by setting the ComVisible attribute for the assembly (in the AssemblyInfo.vb file)
VB Code:
<Assembly: ComVisible(True)>
<Assembly: ClassInterface(ClassInterfaceType.None)>
You can, and should, also set the AssemblyDescription attribute to some value because this will appear in the Project Reference dialog box in VB 6.
VB Code:
<Assembly: AssemblyDescription("Type in some description here")>
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|