managed code和unmanaged code混合debug

12 篇文章 0 订阅

首先:

1. managed code的项目属性中debug页里,"Enable unmanaged code debugging"选上。

2. unmanaged code项目属性的debug页里,Debugger Type设为Mixed。

其次:

  • 如果managed code是dll,unmanaged code是exe,managed code的项目属性中debug页里,start external program设为unmanaged code的exe,然后managed code里F5,需要把unmanaged code项目里的一些需要被debug的文件在managed code项目里打开,以便debug;或者在unmanaged code项目里attach unmanaged code的exe,需要把managed code项目里的一些需要被bebug的文件在unmanaged code项目打开,以便debug.
  • 如果managed code是exe,unmanaged code是dll,则直接F5 managed code项目exe进行debug。

注意:

  • 如果c++的dll中如此定义:extern __declspec(dllexport) int mySum(int x, int y); 并且 calling convention设为_cdecl

则在c#中调用时,需要[DllImport("dll.dll", EntryPoint = "?mySum@@YGHHH@Z", CallingConvention = CallingConvention.Cdecl)] 

 public static extern int mySum (int x,int y);

funciton name "?mySum@@YGHHH@Z"可通过denpendency walker查出来。

  • 如果c++的dll中如此定义:extern “C" __declspec(dllexport) int mySum(int x, int y); 并且 calling convention设为_stdcall

则在c#中调用时,只需要[DllImport("dll.dll"] 

 public static extern int mySum (int x,int y);

因为C#默认calling convention就是_stdcall,并且用了extern “C"之后function name不会mangling,还是mySum.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值