C++结构体
typedef struct tagtmcp_login_info
{
int ip_type;
int user_id;
int error_code;
int control_uint_id;
int privilege_code_size;
int* privilege_code_array;
char session_id[128];
bool login_result;
int userRightLevel;
tagtmcp_login_info()
{
privilege_code_array = NULL;
login_result = false;
}
~tagtmcp_login_info()
{
if(privilege_code_array)
delete [] privilege_code_array;
}
}tmcp_login_info, *ptmcp_login_info;
C#结构体
[StructLayout(LayoutKind.Sequential)]
public struct tmcp_login_info
{
public int ip_type;
public int user_id;
public int error_code;
public int control_uint_id;
public int privilege_code_size;
public int[] privilege_code_array;
public string session_id;
public bool login_result;
public int userRightLevel;
}
C++函数定义
TMCP_INTERFACE_SDK_API(int) tmcp_login_cms(const char* user_name,
const char* password,
tmcp_enum_login_types login_type,
ptmcp_login_info plogin_info,
const char* end_point_url,
const char* local_ip = NULL);
C#调用
[DllImport("tmcp_interface_sdk.dll", EntryPoint = "tmcp_login_cms", ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
private extern static int tmcp_login_cms(string user_name, string password, int login_type, IntPtr plogin_info, string end_point_url, string local_ip);
public static int call_tmcp_login_cms(string user_name, string password, int login_type, ref tmcp_login_info info, string end_point_url, string local_ip)
{
Type type = info.GetType();
int size = Marshal.SizeOf(type);
IntPtr pBuff = Marshal.AllocHGlobal(size);
int ret = tmcp_login_cms(user_name, password, login_type, pBuff, end_point_url, local_ip);
IntPtr ptr = new IntPtr(pBuff.ToInt64() + size);
Marshal.FreeHGlobal(pBuff);
tmcp_login_info plogin_info = (tmcp_login_info)Marshal.PtrToStructure(ptr, type);/*这行代码报错*/
return ret;
}
调用代码:
tmcp_login_info info = new tmcp_login_info();
call_tmcp_login_cms("admin", "12345", 0, ref info, "", "");
出错信息:
“System.AccessViolationException”类型的未经处理的异常出现在 mscorlib.dll 中。
其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
相关推荐
小姐姐炫酷唯美引导页.zip
scratch少儿编程逻辑思维游戏源码-让它们跳起来.zip
少儿编程scratch项目源代码文件案例素材-战斗塔防.zip
前端开发_Vue全家桶_vw适配_vux组件库_mescroll滚动_fastclick优化_mock模拟_less预处理器_移动端脚手架_基于Vue2和Webpack3构建的移动
数据可视化分析_微信小程序开发_JavaScript_Canvas图表渲染_数据助手工具_仿微信小程序数据助手_支持线性图圆环图柱状图条形图_动态效果适配_商业数据分析_移动端数据
少儿编程scratch项目源代码文件案例素材-章鱼怪.zip
音乐流媒体_API开发_网易云音乐接口封装与数据抓取_提供完整的网易云音乐API调用解决方案_包含歌曲搜索_MP3资源获取_歌词解析_播放列表管理_歌手专辑查询_专辑详情展示_MV
物联网与健康监测_基于RISC-V架构ESP32-C3芯片与MAX30102MAX30205传感器_LVGL图形界面与WiFiBLE双模通信的智能手表系统_实时监测心率血氧体温
wangtengfei-hn_EmployeesExample_23540_1745868671962
Android开发_自定义View绘制动画效果_模仿小米手环App首页计步数据展示_实现可自定义目标步数当前步数颜色字体大小圆点尺寸的动态步数统计图表组件_用于健康运动类App展示
少儿编程scratch项目源代码文件案例素材-钻机机器人.zip
scratch少儿编程逻辑思维游戏源码-狂暴坦克.zip
scratch少儿编程逻辑思维游戏源码-拳击.zip
scratch少儿编程逻辑思维游戏源码-魔方冲刺.zip
少儿编程scratch项目源代码文件案例素材-重返危机.zip
杰奇CMS小说网站系统_php53-73_mysql5-MariaDB10_utf8mb4编码_GBK自动转码_INNODB存储引擎_多模块支持_前后台分离_电脑手机双版适配_
linyuan620_StockAnalysisAssistant_17128_1745866117970
本系统采用的数据库是Mysql,使用SpringBoot框架开发,运行环境使用Tomcat服务器,ECLIPSE 是本系统的开发平台。在设计过程中,充分保证了系统代码的良好可读性、实用性、易扩展性、通用性、便于后期维护、操作方便以及页面简洁等特点。
少儿编程scratch项目源代码文件案例素材-足球踩踏者.zip
scratch少儿编程逻辑思维游戏源码-能力实验室争斗.zip