Reputation: 26485
We are working with an existing native application (most likely written in VB) that loads assemblies and calls methods with "Late Binding." We do NOT have access to its source code.
We want to implement this interface in C#, and have the native application call our C# assembly.
Is this something that's possible?
Is this anything we have to do beyond matching the method names and method signatures to make it work?
Upvotes: 1
Views: 1137
Reputation: 99307
If you're trying to call .NET code from VB6 the cleanest way would be to make the C# code appear as a COM object to the VB6 code - so yes, you would need to mark your C# code as ComVisible
and ensure that it looks like the existing COM interface.
Update: Here's an article to get you started.
Upvotes: 2
Reputation: 26485
These are the steps required to make it work:
[ComVisible(true)]
, and make sure to give it a unique [Guid]
attributeProgId
to your class which is normally MyNamespace.MyClass
, but you can add an attribute on your class to override this as well[DispId]
attributes for each method that will be calledregasm.exe
on your assemblyAnd voila! Native code can call your C# via "late binding". I, of course, had to setup several registry keys to make my native application know how to load my assembly, but all is working.
Upvotes: 1