您的位置:程序门 -> .net技术 -> c#



求c++转成c#


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求c++转成c#
发表于:2007-03-07 19:02:58 楼主
c++   源代码

typedef     void   (   callback   *   mpch375_int_routine   )   (     //   中断服务回调程序
puchar       ibuffer   );     //   指向一个缓冲区,提供当前的中断特征数据

bool   winapi   ch375setintroutine(     //   设定中断服务程序
ulong       iindex,     //   指定ch375设备序号
mpch375_int_routine   iintroutine   );     //   指定中断服务回调程序,为null则取消中断服务,否则在中断时调用该程序

我现在写成:

public   delegate   void     intcallback(   intptr   ibuffer);
[dllimport( "ch375dll.dll ")]  
private   static   extern   bool   ch375setintroutine(     //   设定中断服务程序
uint   iindex,     //   指定ch375设备序号
intcallback   iintroutine   );     //   指定中断服务回调程序,为null则取消中断服务,否则在中断时调用该程序  


在调用的时候竟然提示未将对象引用设置到对象的实例


恳求哪位大虾帮忙一下,解决立即送分
发表于:2007-03-07 19:11:201楼 得分:0
up一下
发表于:2007-03-07 19:15:052楼 得分:0
你是怎么调用的
发表于:2007-03-07 19:18:093楼 得分:0
private       void     getdata(intptr   pth)
{}

intcallback   mycallback   =   new   intcallback(getdata);
setintroutine(mycallback);

setintroutine   是我写的另一个函数调用ch375setintroutine的

发表于:2007-03-07 19:20:234楼 得分:0
我觉得应该是那个puchar       ibuffer   的翻译问题。
发表于:2007-03-07 19:45:475楼 得分:0
private       void     getdata(intptr   pth)
{
这里是怎么写的?
如果空着会出错吗?
}
发表于:2007-03-07 19:49:426楼 得分:0
当然不会
发表于:2007-03-07 20:15:597楼 得分:0
puchar   是   typedef   unsigned   char*   puchar吗?
如果是的话用uintptr试一试
发表于:2007-03-07 20:19:188楼 得分:0
你是怎么读取private       void     getdata(intptr   pth)
中pth的数据的?
发表于:2007-03-07 20:25:159楼 得分:0
[dllimport( "ch375dll.dll ")]  
private   static   extern   bool   ch375setintroutine(  
uint   iindex,    
[marshalas(unmanagedtype.functionptr0)]intcallback   iintroutine);
发表于:2007-03-08 09:52:2610楼 得分:0
问题仍未解决....up
发表于:2007-03-08 10:14:4311楼 得分:0
private       void     getdata(intptr   pth)
{}
改成
static   void   getdata(intptr   pth)
{}
试一试
发表于:2007-03-08 10:43:5812楼 得分:0
另一个中断服务倒是可以运行并且正确的。

c++源码:
typedef void (   callback *   mpch375_notify_routine   )   (     //   设备事件通知回调程序
ulong ieventstatus   );     //   设备事件和当前状态(在下行定义):   0=设备拔出事件,   3=设备插入事件
bool winapi ch375setdevicenotify(     //   设定设备事件通知程序
ulong iindex,     //   指定ch375设备序号,0对应第一个设备
pchar ideviceid,     //   可选参数,指向字符串,指定被监控的设备的id,字符串以\0终止
mpch375_notify_routine inotifyroutine   );     //   指定设备事件回调程序,为null则取消事件通知,否则在检测到事件时调用该程序


c#:
public   delegate   void   notifycallback(   ulong     ieventstatus);

[dllimport( "ch375dll.dll ")]
private   static   extern     bool ch375setdevicenotify(     //   设定设备事件通知程序
  uint iindex,     //   指定ch375设备序号,0对应第一个设备
string ideviceid,     //   可选参数,指向字符串,指定被监控的设备的id,字符串以\0终止
notifycallback inotifyroutine   );     //   指定设备事件回调程序,为null则取消事件通知,否则在检测到事件时调用该程序

private   void   notify_routine(ulong   ieventstatus)
{
if(ieventstatus==calvin.ch375.ch375_device_arrival)    
{
this.statusbarpanel2.text= "设备已插上 ";     //将设备插入消息发送到窗体进行处理  
 

 
}
else   if(ieventstatus==calvin.ch375.ch375_device_remove)  
{
 
this.statusbarpanel2.text   = "设备已拔出 ";     //将设备拔出消息发送到窗体进行处理

 
}


}
notifycallback   mynotifycallback   =   new   notifycallback(notify_routine);
ch375.setdevicenotify(mynotifycallback))

}
发表于:2007-03-08 10:44:4813楼 得分:0
问题解决的话,我另外开贴再次专门酬谢....本贴up有分
发表于:2007-03-08 11:02:4714楼 得分:0
关注
发表于:2007-03-08 11:13:5915楼 得分:0
帮顶
发表于:2007-03-09 09:54:4216楼 得分:0
这个问题还是存在....恳请哪位大虾出手相助....
发表于:2007-03-09 10:38:5317楼 得分:0
学习


快速检索

最新资讯
热门点击