If you want to call c++dll in c#, I suggest that you could try the following steps.
First, create a c++ dll and write the following code.
#include "stdafx.h"
#include <Windows.h>
extern "C"
{
__declspec(dllexport) void HelloWorld()
{
MessageBox(0, L"Hello World from DLL!
", L"Hi", MB_ICONINFORMATION);
}
__declspec(dllexport) void ShowMe()
{
MessageBox(0, L"How are u?", L"Hi", MB_ICONINFORMATION);
}
}
Then, right click the properties of the dll, change the Common language Run time Support to Common language Run time Support(/clr).
Like the following picture:
Third, please create a winforms app and write the following code.
**public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("TestDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void HelloWorld();
private void button1_Click(object sender, EventArgs e)
{
HelloWorld();
}
}**
Next, you need to add the correspond dll manually.
Finally, you can get the result.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…