Question

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?

Was it helpful?

Solution 2

These are the steps required to make it work:

  1. Mark your class [ComVisible(true)], and make sure to give it a unique [Guid] attribute
  2. Match your ProgId to your class which is normally MyNamespace.MyClass, but you can add an attribute on your class to override this as well
  3. Put the proper [DispId] attributes for each method that will be called
  4. Compile your assembly and run regasm.exe on your assembly

And voila! Native code can call your C# via "late binding". I, of course, had to setup several registry keys to make my native applciation know how to load my assembly, but all is working.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top