472,779 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

ActiveX and C# Interop

I am having problems getting an ActiveX DLL written in VB6 to call a
method in a C# class library component.

My C# DLL is called CSharpProject.dll and contains a public class
called CSharpClass. In this class is a single public method that
returns the string "Hello

from C sharp".

My VB6 ActiveX DLL references the C# DLL (CSharpProject.dll) using the
type library CSharpProject.tlb. The ActiveX DLL contains two methods,
the first just

returns a string declared within the method, and the second tries to
call the method defined in the C# component.

I then have a simple ASP.Net webform (Webform1.aspx) that creates an
instance of the ActiveX object using client side Javascript.

Everything works fine on my local machine but when I try using it on
another machine I get the following error(s):

1) "File or assembly name CSharpProject, or one of its dependancies,
was not found"


I have tried the following things to resolve the problem:

C# Component:

* I have created the tlb file for the CSharpProject.dll

1) automatically using the setting in Visual Studio "Register for COM
Interop" set to true.
2) using the .net tool tlbexp
3) using regasm /tlb option

(I have also ensured that the .tlb file is registered on other
machines using a tool called Reggie.exe.)

* I have tried creating a strong name for the component and
registering it in the GAC but this doesn't solve the problem.


VB6 ActiveX DLL:

* I have referenced the tlb as per a normal reference.

The code is as follows:

Public Function method1() As String
On Error GoTo fail
foo = "dave"
Exit Function
fail:
foo = "Error in foo occurred in VB ActiveX DLL (" & Err.Description
& ")"
End Function

Public Function method2() As String
On Error GoTo fail
Dim objCSharp As New CSharpProject.CSharpClass
Dim tmp As String
tmp = objCSharp.foo()
method2 = tmp
Exit Function
fail:
method2 = "Error occurred in VB ActiveX DLL (" & Err.Description &
")"
End Function

NOte: I have also tried using the following code to declare and
instantiate the C# class -

Dim objCSharp
Set objCSharp = CreateObject("CSharpProject.CSharpClass")

However this returns the following error message from the VB6 ActiveX
DLL: "Object doesn't support this property or method."


javascript:

var obj = new ActiveXObject("VBActiveXDLL.VBClass1");
alert(obj.method1());
alert(obj.method2());

All works fine on my local machine but when I copy/register/install
all the components on another machine (which has Visual Studio.Net and
v6 installed) it

doesn't work.

Any suggestions, comments, or ideas would be much appreciated
Thanks

Craig
Nov 16 '05 #1
1 8531
Hi,

I am not sure calling c#.dll into activex vb6.

What i did before i calling c#.dll into vb6 by com interop.

1. Yeah i did register as com interop.
2. I do not recommend to use static methods or variables coz vb6 doesn't understand it.
3. Be careful when you past in array for ref and out keywords.
4. Each function called in vb6 must be assigned to variables. Void methods not allowed.
5. Limits the assembly details written in AssemblyInfo

Hope these guidelines might help you. Correct me if i am wrong.
--
Regards,
Chua Wen Ching :)
"Craig" wrote:
I am having problems getting an ActiveX DLL written in VB6 to call a
method in a C# class library component.

My C# DLL is called CSharpProject.dll and contains a public class
called CSharpClass. In this class is a single public method that
returns the string "Hello

from C sharp".

My VB6 ActiveX DLL references the C# DLL (CSharpProject.dll) using the
type library CSharpProject.tlb. The ActiveX DLL contains two methods,
the first just

returns a string declared within the method, and the second tries to
call the method defined in the C# component.

I then have a simple ASP.Net webform (Webform1.aspx) that creates an
instance of the ActiveX object using client side Javascript.

Everything works fine on my local machine but when I try using it on
another machine I get the following error(s):

1) "File or assembly name CSharpProject, or one of its dependancies,
was not found"


I have tried the following things to resolve the problem:

C# Component:

* I have created the tlb file for the CSharpProject.dll

1) automatically using the setting in Visual Studio "Register for COM
Interop" set to true.
2) using the .net tool tlbexp
3) using regasm /tlb option

(I have also ensured that the .tlb file is registered on other
machines using a tool called Reggie.exe.)

* I have tried creating a strong name for the component and
registering it in the GAC but this doesn't solve the problem.


VB6 ActiveX DLL:

* I have referenced the tlb as per a normal reference.

The code is as follows:

Public Function method1() As String
On Error GoTo fail
foo = "dave"
Exit Function
fail:
foo = "Error in foo occurred in VB ActiveX DLL (" & Err.Description
& ")"
End Function

Public Function method2() As String
On Error GoTo fail
Dim objCSharp As New CSharpProject.CSharpClass
Dim tmp As String
tmp = objCSharp.foo()
method2 = tmp
Exit Function
fail:
method2 = "Error occurred in VB ActiveX DLL (" & Err.Description &
")"
End Function

NOte: I have also tried using the following code to declare and
instantiate the C# class -

Dim objCSharp
Set objCSharp = CreateObject("CSharpProject.CSharpClass")

However this returns the following error message from the VB6 ActiveX
DLL: "Object doesn't support this property or method."


javascript:

var obj = new ActiveXObject("VBActiveXDLL.VBClass1");
alert(obj.method1());
alert(obj.method2());

All works fine on my local machine but when I copy/register/install
all the components on another machine (which has Visual Studio.Net and
v6 installed) it

doesn't work.

Any suggestions, comments, or ideas would be much appreciated
Thanks

Craig

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sorin | last post by:
Hi all I have a .NET application that is using few ActiveX DLL wrote in VB6. I managed to get the most from my previous VB6 controls by using them in .NET but sometimes when I am using my...
1
by: Rich S. | last post by:
Hello, I have imported an ActiveX control and I'm trying to use it inside a C# class. The problem is that since the event handlers are required to be "static" functions, I can't reference the...
5
by: andy.g.ward | last post by:
I keep getting this when trying to create an MFC activex control in a c# windows service - anyone got any ideas what the missing module could be??? Exception thrown :...
1
by: Mehr H | last post by:
I have been working on this for several days and am still have had no success in achieving this. Pleae help. It seems that documentation for this is very limited. I have looked in several books and...
3
by: Jeffery Franzen | last post by:
Anyone know where the documentation is regarding Activex controls in asp web forms? I'm using VS.NET 2002 enterprise and am trying to use Activex controls in vb.net web form app. I do the add...
1
by: Kevin Frey | last post by:
We have an ActiveX control that we added as a reference to a *Console* C# testbed. The testbed functions, except that: a. On VS 2003, performance is fine, but on VS 2005, performance is reduced...
23
by: Galen Somerville | last post by:
A VB6 ActiveX.exe raises an event which is seen by the VB6 App. Same setup in VB2005. The event to be raised is in form frmSweep. As in VB6, frmSweep is hidden when the events take place. I...
4
by: Steve Alpert | last post by:
With JScript in html, the object codebase can be given a version number which will do a pull from the server if the user has an earlier version. Is there a comparable setup inside an interop...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.