DannyvdKraan
New member
- Joined
- May 12, 2009
- Messages
- 2
- Programming Experience
- 1-3
Hello my saviors (I hope),
I have a little problem getting my .NET component to work in VB6. I have created in Visual Studio 2008 with VB.NET using the COM Class template a assembly which I want to call in VB6. This is the code:
<ComClass(TestTemplateClass.ClassId, TestTemplateClass.InterfaceId, TestTemplateClass.EventsId)> _
Public Class TestTemplateClass
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "6a22b94d-74e7-4bb7-ad90-2398faa72ef5"
Public Const InterfaceId As String = "c78aed76-d3d3-4af7-bd5f-d7e8775669d1"
Public Const EventsId As String = "f2fd0f05-acbe-4e4d-a5be-e19a0d259bcf"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Public Function SayHello() As String
Return "Hello!"
End Function
End Class
As you can see it's pretty straight forward. It does all the appropiate decorating/registering and whatnot for yah using the template. It only has one method called 'SayHello' which I'm calling in VB6. I clicked 'build' and presto... it created the .dll/.tlb/.pdb
Then in VB6 I referenced the .tlb (can't reference the .dll directly) and created a form with one button. In the click event I have the following code:
Private Sub cmdOK_Click()
Dim o As TestTemplateClass
Set o = New TestTemplateClass
MsgBox o.SayHello
End Sub
This works! No problem. So what's the problem you might ask? Well the executable doesn't work. When I simply make the executable in the studio and dubble click it I get the run time error: "File or assembly name 'TestTemplate', or one of it's dependencies, was not found." I've tried to:
- move the dll + tlb to the same directory the .exe is in;
- move these files to the same directory vb.exe is in;
- move these files to c:\windows\system32
This all didn't help. Then I created a package using the Package & Deployment Wizard. It complains indeed about not knowing the dependancies of 'TestTemplate' assembly, but it goes ahead and create my package anyways. I install my tiny test VB6 application by running setup and it apparantly copies TestTemplate.tlb to my c:\windows\system32 directory. But when I run this installed application I get: "Class does not support automation or does not support expected interface".
To cut this long story short. Can someone please explain to me why it works in my IDE but not in an executable? It's all done on the same development machine (mine) with Win XP and Framework 3.5 installed. I'm at my wits end after 3 days digging, so I really need some help.
Thnx in advance for the replies.
I have a little problem getting my .NET component to work in VB6. I have created in Visual Studio 2008 with VB.NET using the COM Class template a assembly which I want to call in VB6. This is the code:
<ComClass(TestTemplateClass.ClassId, TestTemplateClass.InterfaceId, TestTemplateClass.EventsId)> _
Public Class TestTemplateClass
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "6a22b94d-74e7-4bb7-ad90-2398faa72ef5"
Public Const InterfaceId As String = "c78aed76-d3d3-4af7-bd5f-d7e8775669d1"
Public Const EventsId As String = "f2fd0f05-acbe-4e4d-a5be-e19a0d259bcf"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Public Function SayHello() As String
Return "Hello!"
End Function
End Class
As you can see it's pretty straight forward. It does all the appropiate decorating/registering and whatnot for yah using the template. It only has one method called 'SayHello' which I'm calling in VB6. I clicked 'build' and presto... it created the .dll/.tlb/.pdb
Then in VB6 I referenced the .tlb (can't reference the .dll directly) and created a form with one button. In the click event I have the following code:
Private Sub cmdOK_Click()
Dim o As TestTemplateClass
Set o = New TestTemplateClass
MsgBox o.SayHello
End Sub
This works! No problem. So what's the problem you might ask? Well the executable doesn't work. When I simply make the executable in the studio and dubble click it I get the run time error: "File or assembly name 'TestTemplate', or one of it's dependencies, was not found." I've tried to:
- move the dll + tlb to the same directory the .exe is in;
- move these files to the same directory vb.exe is in;
- move these files to c:\windows\system32
This all didn't help. Then I created a package using the Package & Deployment Wizard. It complains indeed about not knowing the dependancies of 'TestTemplate' assembly, but it goes ahead and create my package anyways. I install my tiny test VB6 application by running setup and it apparantly copies TestTemplate.tlb to my c:\windows\system32 directory. But when I run this installed application I get: "Class does not support automation or does not support expected interface".
To cut this long story short. Can someone please explain to me why it works in my IDE but not in an executable? It's all done on the same development machine (mine) with Win XP and Framework 3.5 installed. I'm at my wits end after 3 days digging, so I really need some help.
Thnx in advance for the replies.