How to verify that C#/.NET COM object is actually a COM object?
See the question and my original answer on StackOverflowOne quick way of doing it is to use the dynamic feature of .NET which is very useful for COM programming
So if you class is defined like this (I don't personally use COM interfaces with .NET, but that changes nothing if the interface is dual), note I've added a progid which is good COM practise:
[Guid("0135bc5c-b248-444c-94b9-b0b4577f5a1a")]
[ProgId("MyComponent.TwoWay")]
[ComVisible(true)]
public class TwoWay
{
public void Initialize(string IPAddress, long Port, long MaxPacketSize)
{
Console.WriteLine(IPAddress);
}
// other methods...
}
Then I can test it using .NET like this (no need to create a TLB, just register it using regasm):
var type = Type.GetTypeFromProgID("MyComponent.TwoWay");
dynamic twoway = Activator.CreateInstance(type);
twoway.Initialize("hello", 0, 0);
The inconvenient is you don't have auto completion, you just have to take care to pass arguments that fit. And .NET is smart enough to convert Int32
into Int64
(note the C# long
you use is 64-bit wide).