create a wrapper for the unmanaged C++ dll file

I have a .dll written in C++ that I would like
to use in C# program. Is it possible to do that and how If I try to add with
Add Reference, I can't.

Tell me how to create a wrapper for the unmanaged C++ dll file.

Willfin



Answer this question

create a wrapper for the unmanaged C++ dll file

  • BeezelDub

    Platform Invoke or P/Invoke is what you need. Please check out this tutorials: http://msdn.microsoft.com/library/default.asp url=/library/en-us/csref/html/vcwlkplatforminvoketutorial.asp

    As a thumb rule when designing native interop wrappers is that you should hide as much information as possible from the user (the managed program). If your native function takes lots of parameters that you would never use in managed code, you should hide them inside the wrapper.

    You should also handle all possible native errors inside the wrapper, and throw Managed Exceptions if needed. You can create your custom Exception derived classes to get custom exceptions. Also remeber to clean unmanaged resources (if any) in wrappers Dispose method.

  • create a wrapper for the unmanaged C++ dll file