Interaction with C# DLLs should be done with COM, not with Interop.Call. You need to make your classes and methods "ComVisible" so that they are exposed for COM in the DLL. Have a look at trying to create a c# COM server.
quote:Originally posted by Matti
Interaction with C# DLLs should be done with COM, not with Interop.Call. You need to make your classes and methods "ComVisible" so that they are exposed for COM in the DLL.
Thus, not any .NET DLL can be called though. It needs to be properly prepped to handle COM.
Hi, I created a new class just like the VB sample code.
using System;
using System.Runtime.InteropServices;
namespace MyDLL
{
[ComVisible(true)]
public class Operations
{
[ComVisible(true)]
public string getValue1(string sParameter)
{
switch (sParameter)
{
case "a":
return "A was chosen";
I have tried:
Interop.Call("C:\\Program Files\\Messenger Plus! Live\\Scripts\\MySecondScript\\MyDLL.dll", "getValue1", "a");
and I received the error: Interop.Call failed to locate function "getValue1"
I have also tried: var myObj = new ActiveXObject("MyDLL.Operations"); and I receive the error: unknown (code: -2147024894)
It doesn't matter at all if it's C#/VB.NET, COM classes must have a parameterless constructor in order to register correctly. Sorry if I wasn't clear in the first place
Just made a quick test and it's working:
Spoiler:
C# code:using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MyDLL
{
[ComVisible(true)]
public class Operations
{
/// <summary>
/// Parameterless constructor required in order to register correctly
/// </summary>
public Operations()
{
}
public string getValue1(string sParameter)
{
switch (sParameter)
{
case "a":
return "A was chosen";
It doesn't matter at all if it's C#/VB.NET, COM classes must have a parameterless constructor in order to register correctly. Sorry if I wasn't clear in the first place
ah yeah, but that's not what I meant. The code you showed for the parameterless constuctor (underlined bit) is VB.NET, not C#...
Also, in the C# code I showed, which is a working code apparently, they don't have that parameterless constructor, yet it does register perfectly according to the article though, so what are they doing differently?
Either way, also according to the code I showed, you best add a few more things to it in order to make it good COM Interop.
This post was edited on 10-23-2010 at 09:33 AM by CookieRevised.