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

esnis 2007-01-11 05: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#里调用,请问得如何做
...全文
147 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
GeminiXXXCC 2007-01-11
  • 打赏
  • 举报
回复
用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]什么的了。
zjh222 2007-01-11
  • 打赏
  • 举报
回复
你明明知道C#不能做C++能做的全部事情,你却偏偏要这样做.

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧