用于C ++应用程序的C#DLL [英] C# DLL for C++ Application

查看:59
本文介绍了用于C ++应用程序的C#DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有一个C ++应用程序,可以使用

特定接口与C ++ DLL进行通信。我想知道,如果可以使用相同的接口创建一个具有相同接口的
C#DLL。 C ++ DLL公开的函数是
是这些:


externC _declspec(dllexport)int _stdcall f1(int a,char * b,int c,int

d);

extern" C" _declspec(dllexport)void _stdcall f2(void)

extern" C" _declspec(dllexport)int _stdcall f3(char * a,char * b,int c)

externC _declspec(dllexport)int _stdcall f4(char * a,_T ** b)


其中_T类型是结构:


typedef struct

{

char x;

char y [128];

void * z;

} _T;


在函数f1中,b是b。参数应用程序预分配数组

字符(128个字符)。 a也是如此。和b函数f3中的参数

和a函数f4中的参数。 b表示b。函数f4中的参数是在DLL中动态分配的
。是否有可能将此DLL

接口重写为C#?怎么样?

解决方案

我想不是。 .net dll的内部结构(和/ b $ b完全不相关的是用来编写它的语言)与ac / c ++ dll非常相似,所以我怀疑如果一个c ++程序能够

链接到它。


Martin写道:

你好。我有一个C ++应用程序,可以与具有特定接口的C ++ DLL进行通信。我想知道,如果有可能创建一个具有相同接口的C#DLL。 C ++ DLL公开的功能如下:

externC _declspec(dllexport)int _stdcall f1(int a,char * b,int c,int
d);
externC _declspec(dllexport)void _stdcall f2(void)
extern" C" _declspec(dllexport)int _stdcall f3(char * a,char * b,int c)
externC _declspec(dllexport)int _stdcall f4(char * a,_T ** b)

_T类型是一种结构:

typedef struct
{
char x;
char y [128];
void * z;
} _T;

在函数f1中,b是b。参数应用程序预分配的字符数组(128个字符)。 a也是如此。和b函数f3中的参数
和a。函数f4中的参数。 b表示b。函数f4中的参数是在DLL中动态分配的。是否可以将此DLL
接口重写为C#?怎么样?




这是可能的,但是很难,如果没有MC ++你就不能这样做(你可以在MC ++中写一下封装dll )。


£ukasz


你能发布一个源代码如何做到这一点吗?

Hi. I have a C++ application that can communicate with C++ DLL with
specific interface. I would like to know, if it is possible to create a
C# DLL with the same interface. The functions which the C++ DLL exposes
are these:

extern "C" _declspec(dllexport) int _stdcall f1(int a,char *b,int c,int
d);
extern "C" _declspec(dllexport) void _stdcall f2(void)
extern "C" _declspec(dllexport) int _stdcall f3(char *a,char *b,int c)
extern "C" _declspec(dllexport) int _stdcall f4(char *a,_T **b)

where the _T type is a structure:

typedef struct
{
char x;
char y[128];
void *z;
}_T;

In function f1 is the "b" parameter an application preallocated array
of chars (128 chars). So are the "a" and "b" parameters in function f3
and "a" parameter in function f4. The "b" parameter in function f4 is
dynamically allocated in DLL. Is it possible to rewrite this DLL
interface to C#? How?

解决方案

i think not. the internall structure of a .net dll (and it is
completely irrelevant what language was used in writing it) is very
different from a c/c++ dll, so i doubt if a c++ program will be able to
link to it.


Martin wrote:

Hi. I have a C++ application that can communicate with C++ DLL with
specific interface. I would like to know, if it is possible to create a
C# DLL with the same interface. The functions which the C++ DLL exposes
are these:

extern "C" _declspec(dllexport) int _stdcall f1(int a,char *b,int c,int
d);
extern "C" _declspec(dllexport) void _stdcall f2(void)
extern "C" _declspec(dllexport) int _stdcall f3(char *a,char *b,int c)
extern "C" _declspec(dllexport) int _stdcall f4(char *a,_T **b)

where the _T type is a structure:

typedef struct
{
char x;
char y[128];
void *z;
}_T;

In function f1 is the "b" parameter an application preallocated array
of chars (128 chars). So are the "a" and "b" parameters in function f3
and "a" parameter in function f4. The "b" parameter in function f4 is
dynamically allocated in DLL. Is it possible to rewrite this DLL
interface to C#? How?



It is possible, but difficult and you cannot do that without MC++ (you
can write "wrapper" dll in MC++).

£ukasz


Can you post a source code how this could be done?


这篇关于用于C ++应用程序的C#DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆