Call a native C++ dll from My C# windows app
I have a C++ dll that has a function exported like so:
__declspec(dllexport) int WINAPI StartServer() ;
I wish to call this function from my C# Windows application. How do I do this??
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Sam HobbsRank #107 · 20.5K reputationPosted Nov 10, 2009, 6:05 AM EST
In the following, you need to change dllname to the dll name. Add the using to the otehr that is in the program. The DllImport must be in a class.
using System.Runtime.InteropServices;.
.
.
[DllImport("dllname.dll")]
private static extern void StartServer();
.
.
.
StartServer();