一、C#调用C++的DLL搜集整理并测试通过的数据类型转换方式,可能不太全,大家可以多测试。
C++ |
C# |
Int32_t |
Int/Intptr |
Int32_t & |
ref InPtr /out Inptr |
const char* |
string |
bool |
Boolean |
结构体* 结构体变量1 |
ref 结构体 结构体变量2 |
char 数组 |
string |
uint32_t |
uint |
回调函数 |
委托 |
Void * |
Intptr |
int |
int |
结构体 变量1 |
结构体 变量2 |
结构体 ** 变量1 |
Ref 结构体 变量2 |
Int * |
Ref int |
const 结构体 * result |
IntPtr |
C++ |
C# |
Int32_t |
Int/Intptr |
Int32_t & |
ref InPtr /out Inptr |
const char* |
string |
bool |
Boolean |
结构体* 结构体变量1 |
ref 结构体 结构体变量2 |
char 数组 |
string |
uint32_t |
uint |
回调函数 |
委托 |
Void * |
Intptr |
int |
int |
结构体 变量1 |
结构体 变量2 |
结构体 ** 变量1 |
Ref 结构体 变量2 |
Int * |
Ref int |
const 结构体 * result |
IntPtr |
二、结构体对应
1.c++常规结构体:
typedef struct LoginInfo
{
char szIp[46]; // 服务IP
uint32_t nPort; // 服务端口
char szUsername[64]; // 用户名
char szPassword[64]; // 密码
protocol_version_e nProtocol; // protocol_version_e为枚举
}Login_Info_t;
则c#对应的结构体可以这样写
public struct Login_Info_t
{
/// <summary>
/// 服务IP
/// </summary>