关于调用C的动态链接库的问题(较难,老鸟不妨也进来看看)
我在C#工程里面调用C的一个动态链接库,它的函数原型是
Dll 中函数的原型
int iaTrapSend(const char* psEnterpriseOID, int iGerneric, int iSepecific,
STUPARAM *pTrapParam, int iCount);
其中STUPARAM 定义如下
结构类型STUPARAM定义为:
typedef struct
{
char m_szParamName[256]; //参数名
char m_szInstance[256];//参数事例号
unsigned char m_ucType;//参数类型
unsigned short m_usVLen;//参数长度
unsigned char m_szValue[256];//参数值
unsigned short m_usError;//读写参数时的错误信息
}STUPARAM
我的代码如下:
[StructLayout(LayoutKind.Sequential)]
public struct STUPARAM
{
public char[] m_szParamName; //参数名
public char[] m_szInstance; //参数事例号
public char m_ucType; //参数类型
public ushort m_usVLen; //参数长度
public char[] m_szValue;//参数值
public ushort m_usError; //读写参数时的错误信息
}
public static extern int iaTrapSend(string psEnterpriseOID, int iGerneric, int iSepecific,
ref STUPARAM[] pTrapParam, int iCount);
但是每次调用都不成功,我单独写了一个类似的东西来测试发现应该是STUPARAM类型转换的问题,不知道哪位有办法??