A Simple C# DLL - how do I call it from Excel, Access, VBA, VB6?
You can't access a static member via COM interop. In fact your code doesn't even compile, the method should be in a class. Here is how you can do it:
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("01A31113-9353-44cc-A1F4-C6F1210E4B30")] //Allocate your own GUID
public interface _Test
{
string HelloWorld { get; }
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("E2F07CD4-CE73-4102-B35D-119362624C47")] //Allocate your own GUID
[ProgId("TestDll.Test")]
public class Test : _Test
{
public string HelloWorld { get { return "Hello, World! "; } }
}
The project properties Build tab, select Register for COM interop. So you can see the results quickly. To install the dll on another machine you need to use regasm.
To then consume this:
Dim o : Set o = CreateObject("TestDll.Test")
MsgBox o.HelloWorld
You can also reference the dll and use early binding:
Dim o As TestDll.Test
Set o = New TestDll.Text
MsgBox o.HelloWorld
Calling a VB6 method from a .NET DLL
As VB6 creates COM DLLs, Visual Studio should have no problems generating an interop stub for you. Simply add a reference to the VB6 DLL from your .NET project by selecting Add Reference in Visual Studio and finding your DLL under the COM tab. Make sure the VB6 DLL is registered on your machine before you do this.
Related Topics
How to Wait for a Backgroundworker to Cancel
Apply Properties Values from One Object to Another of the Same Type Automatically
Entity Framework - Code First - Can't Store List<String>
What's the Difference Between Ienumerable and Array, Ilist and List
Addbusinessdays and Getbusinessdays
Embedding Assemblies Inside Another Assembly
How to Create a Wpf Usercontrol with Named Content
Why Is Httpcontext.Current Null After Await
Generate and Sign Certificate Request Using Pure .Net Framework
C# 6.0 Features Not Working with Visual Studio 2015
How to Download a File from a Website in C#
Performance Difference for Control Structures 'For' and 'Foreach' in C#
Are Lambda Expressions in C# Closures