c#调用c++ api函数之参数类型问题-急(高人教教我)

jackyped jackyped 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
c#调用c++ api函数之参数类型问题

c++函数定义如下
extern "C"
{

struct colorstruct
{
double dbValueInterval;
CString str;
IColorPtr ipColor;
colorstruct()
{
str = _T(" ");
dbValueInterval = 0.0;
ipColor.CreateInstance(CLSID_RgbColor);
}


};

__declspec(dllexport) void CressmantestforSK (int a,int irad,float * rads,int isiz,int jsiz,float dbCellSize,double lnmin,double lnmax,double ltmin,double ltmax,long stnnum,float *stnlon,float *stnlat,float *stnrpt,float *grid,colorstruct *colorArray,int iLineNum,float NoDefineVale);


}

C#中extern 如下
[DllImport("CressmanforSk24.dll")]
public extern static void CressmantestforSK( //__declspec(dllexport) void CressmantestforSK (
int a, // int a,
int irad, // int irad,
Single[] rads, // Single * rads,
int isiz, // int isiz,
int jsiz, // int jsiz,
Single dbCellSize, // Single dbCellSize,
double lnmin, // double lnmin,
double lnmax, // double lnmax,
double ltmin, // double ltmin,
double ltmax, // double ltmax,
long stnnum, // long stnnum,
Single[] stnlon, // Single *stnlon,
Single[] stnlat, // Single *stnlat,
Single[] stnrpt, // Single *stnrpt,
out Single[] grid, // Single *grid,
colorstruct[] colorArray, // colorstruct *colorArray,
int iLineNum, // int iLineNum,
Single NoDefineVale // Single NoDefineVale
); // );


public struct colorstruct
{
/// <summary>
/// 数值
/// </summary>
[MarshalAs(UnmanagedType.R8)]
public double dbValueInterval;// = 0;
/// <summary>
/// 名称
/// </summary>
[MarshalAs(UnmanagedType.LPStr)]
public string str;// = " "
/// <summary>
/// 颜色
/// </summary>
[MarshalAs(UnmanagedType.Interface)]
public IColor ipColor;// = new RgbColorClass()


//void colorstruct()
//{
// str = _T(" ");
// dbValueInterval = 0.0;
// ipColor.CreateInstance(CLSID_RgbColor);
//}
};

报错 :尝试读取或写入受保护的内存,内存已损坏


初步确定是参数类型对应的问题,谁能帮帮我啊
msn:jpu_jacky@eyou.com
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
jackyped
C# 111,129 成员 642,538 内容