当前位置:编程学习 > C#/ASP.NET >>

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

详细是这样的,有一个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#里调用,请问得如何做
--------------------编程问答-------------------- 你明明知道C#不能做C++能做的全部事情,你却偏偏要这样做. --------------------编程问答-------------------- 用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]什么的了。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,