Search code examples
c#visual-c++dlldllexport

Call a function of DLL (written in VC++) from C#


I have a DLL written in VC++ and I need to make use of the functions (available in DLL) in my C# Forms application. Tried using the export features available but nothing worked for me. Also I tried other possible solutions that I managed to get by browsing like the wrappers, p Invoke etc. Will be thankful if someone suggest a good working solution.


Solution

  • If your C++ code is generated as native code you can use the DllImportAttribute.

    [DllImport("yourdll.dll")]
    public extern returnType FunctionName (int p1, string p2); // the parameters are the same as the C++ function
    

    For more information see the following link: http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx

    Good luck