Search code examples
c#apivb6

Compile C# code into a DLL and access that C# DLL from VB6.0 declaring it as an API call


In my VB6.0 days I used tons of windows API. So I got the idea that all the API methods that I declared are pretty much procedure based - or it has a procedure based entry point.

My question:

I have written some code in C# which I need to access from VB6.0. Is it possible to compile my C# code into a DLL and access that C# DLL from VB6.0 declaring it as an API call? If so, how is this done ?

(I have already tried making my C# DLL COM compliant, and it worked - but I would like to try the above mentioned approach anyway)


Solution

  • No, you can't expose the entry points to your C# DLL as Win32-style APIs. If you really, really need to create procedural entry points for a .NET library, probably the best thing to do is create a mixed-mode wrapper library using C++/CLI. But this seems like hard work: exposing your C# classes as COM objects is likely to be a lot less effort and much easier to maintain.