C#引用C++写的dll文件时,是否需要EntryPoint参数,要看C++声明方式是一下哪一种:
一、若为C-Style方式的声明,则C#引用时不需要EntryPoint参数:
//cpp头文件声明,C-style方式声明,C#引用时不需要EntryPoint参数
extern "C" {
void API_EXPORT _cdecl printC(char* msg);
int API_EXPORT _stdcall addC(int a, int b);
}
***********************************************************
//cpp函数体
///C-Style export with a C-Sytle call (cdecl)
extern "C" void API_EXPORT _cdecl printC(char* msg) {
printf(msg);
printf("printed from a _cdecl function\n");
}
///C-Style export with C++ call (stdcall)
extern "C" int API_EXPORT _stdcall addC(int a, int b) {
int c = a + b;
printf("%d + %d = %d\n", a, b, c);
return c;
}
二、若不是C-Style方式的声明,则C#引用时需要填EntryPoint参数。
//c++头文件声明,这种声明不是C-Style方式声明,C#引用时需要带EntryPoint参数
void API_EXPORT _stdcall printS(char* msg);
********************************************************************
//C++函数体
///C++ Style export with C++ call (stdcall)
void API_EXPORT _stdcall printS(char* msg) {
printf(msg);
printf("printed from a _stdcall function\n");
}
EntryPoint参数可以使用eXeScope,或VC6.0自带的dependency查看C++生成的dll。
可参考:https://www.cnblogs.com/mfrbuaa/p/3806388.html
整体引用例程可参考:https://github.com/Xinnx/MarshalingTest