HighTechTalks DotNet Forums  

ActiveX and C# Interop

CSharp microsoft.public.dotnet.languages.csharp


Discuss ActiveX and C# Interop in the CSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default ActiveX and C# Interop - 07-01-2004 , 03:13 AM






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

Reply With Quote
  #2  
Old   
Chua Wen Ching
 
Posts: n/a

Default RE: ActiveX and C# Interop - 07-01-2004 , 04:53 AM






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:

Quote:
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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.