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



请问高手,c++如何改写成c#


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


请问高手,c++如何改写成c#
发表于:2007-01-11 17:53:47 楼主
详细是这样的,有一个c++开发的动态链接库,在c里调用是这样的
struct   result_t{  
int   start;    
int   length;  
unsigned   char   pos_id;
int   word_id;  
};  
新增一个调用函数:  
tgws_api   const   result_t   *   tgws_paragraphprocessa(const   char   *sparagraph,int   *presultcount);  
3.具体的调用示例如下:  
const   result_t   *pvecresult;  
int   ncount;  
pvecresult=tgws_paragraphprocessa(sinput,&ncount);  
for   (int   i=0;i <ncount;i++)  
{  
printf( "start=%d   length=%d   word_id=%d   pos_id=%d\n ",  
pvecresult[i].start,  
pvecresult[i].length,  
pvecresult[i].word_id,  
pvecresult[i].pos_id  

);  
}  


现在要在c#里调用,请问得如何做
发表于:2007-01-11 19:13:001楼 得分:0
你明明知道c#不能做c++能做的全部事情,你却偏偏要这样做.
发表于:2007-01-11 20:16:542楼 得分:0
用c++/cli写一个托管类的静态函数调用你的c++开发的动态链接库函数
public   ref   class   nativecode
{
public:
      static   void   nativemethed()
      {
            const   result_t   *pvecresult;  
            int   ncount;  
            pvecresult=tgws_paragraphprocessa(sinput,&ncount);  
      }
};
编译成.net下的dll以后,在c#项目中加入这个dll引用,
然后在需要时候直接可以调用
nativecode.nativemethed();
这样应该比较简单吧,我们公司不少c下的函数都是这么调用的。
省得每次都搞什么[importdll]什么的了。


快速检索

最新资讯
热门点击