473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.d ll 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.t lb. 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.d ll

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.C SharpClass
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("C SharpProject.CS harpClass")

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.VB Class1");
alert(obj.metho d1());
alert(obj.metho d2());

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 8648
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.d ll 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.t lb. 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.d ll

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.C SharpClass
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("C SharpProject.CS harpClass")

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.VB Class1");
alert(obj.metho d1());
alert(obj.metho d2());

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
1173
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 ActiveX DLL in debug mode the associated Interop DLL in the BIN folder is deleted and my DLL Reference in the .NET project is broken as I see the Yellow Sign on top of it. I think that some illegal operation on the ActiveX DLL side may force .NET to...
1
1202
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 instance members of my class from inside them. As of now, it gives me compile errors because I am referencing non-static members from the static event handlers.
5
8780
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 : System.IO.FileNotFoundException: The specified module could not be found. at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid) at System.Windows.Forms.AxHost.CreateWithoutLicense() at...
1
3114
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 they all seem to say either nothing about this or that this is "out of the scope of this book", even "Professional ASP.NET". I have a ActiveX component that I'd like to expose through a .NET wrapper so in the case that a client browses to my...
3
2521
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 control to pallete and then add a reference. I get the interop dll added to bin folder. I did this with the MediaPlayer activex control as a simple case to to try and get it working. I set the control to autostart via the html parameter tag for...
1
1706
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 approximately 50-fold. b. There is a huge memory leak. When the "essence" of application is changed from a console application to a GUI application, both of the above problems disappear. There is no memory leak, and no performance problem on VS...
23
3478
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 know by actions on the screen and sounds in the speakers that VB2005 is using the ActiveX.exe correctly. However the events are never raised !!!
4
1542
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 wrapper? The generated wrapper seems to have no such ability out of the box. thanks, /steveA
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.