从非托管C ++动态调用C#dll
你好,
我对C#和C/C ++之间的互操作有疑问.就是这种情况:
-我需要开发一个C#dll(MS VS2010)
-C ++软件(C ++ Builder IDE)必须调用此dll才能执行某些操作
这是调用方法(C ++)的代码:
Hi there,
I have a question about Interop between C# and C/C++. That''s the situation :
- I need to develop a C# dll (MS VS2010)
- A c++ software (C++ Builder IDE) must call this dll in order to do some stuff
This is the code of the calling method (C++) :
// Loading DLL
if (enCr == OK)
{
asDllName = asTagValue;// + ".dll";
sprintf(aucNameDLL, "%s\\%s\\%s.dll", ExtractFileDir(argv[0]).c_str(), asDllName.c_str(), asDllName.c_str());
if (!(hinstDLL=LoadLibrary(aucNameDLL)))
{
enCr = ER_LOAD_DLL;
}
}
// Launch method
if (enCr == OK)
{
if ((ImpDllRequest = (DLL_FUNC_REQQUEST)GetProcAddress(hinstDLL, "enXmlRequest"))==NULL)
{
enCr = ER_LOAD_FUNCTION;
}
}
我在这里找到了有关此类问题的一些信息:
http://www.codeproject.com/KB/cs/ManagedCOM.asp [ ^ ]
但是我必须输入C ++软件的静态信息.
是否存在一种以动态方式调用C#dll的方法,就像我的示例一样.
不确定我的解释不是很稳定,但是英语不是我的外语,所以只要提出问题,我就会尽力回答.
BaptX
I found some informations about this kind of problem here :
http://www.codeproject.com/KB/cs/ManagedCOM.asp[^]
But I have to put in the C++ software static informations.
Does exists a way to call C# dll in a dynamic way, like my example over.
Not sure my explanations are understable but English is not my foreign language, so just ask questions, I will try to answer.
BaptX
如果您想将C#dll引入本机VC ++(VC 6.0)运行时,则可以
使用regasm.exe将C#dll注册为COM类并调用函数...
如果您使用/clr选项在vc ++(VC ++ studio 2008)中构建项目,则只需在C ++软件项目中添加C#dll的引用即可....
这很清楚吗?还是您需要更多... ??
If you want take C# dll in to native VC++ (VC 6.0 ) runtime then you may
register C# dll as COM class using regasm.exe and call functions ...
and If you are building your projects in vc++ ( VC++ studio 2008 ) with /clr option then you can just add reference of C# dll in C++ software project ....
is this clear or you need something more ...??
.NET dll可使用LoadAssembley动态加载.
您不能直接从C ++调用.net dll,除非它是使用/CLR混合管理和未管理的dll.
在您遇到的情况下,我将要做的是创建一个混合的C ++/.NET dll来包装您的c#.Net DLL,然后从C ++ dll调用C ++/.NET dll directlt,然后从C ++/.NET调用C#.NET DLL DLL如下:
C ++ DLL ---调用- C ++/NET(CLR)DLL ---调用----> C#.NET程序集
.NET dlls can be loaded dynamically using LoadAssembley.
You can''t call a .net dll directly from C++ unless it is a mixed managed and unmanged dll using /CLR.
What I would do in you situation is to create a mixed C++/.NET dll to wrap your c#.Net DLL then call the C++/.NET dll directlt from the C++ dll and call the C#.NET DLL from the C++/.NET DLL as follows:
C++ DLL ---calls---> C++/NET (CLR) DLL---calls----> C#.NET Assembley
如果我理解正确,您说过我需要创建一个DLL,该DLL将在我的C ++软件和C#DLL之间建立接口?
软件->混合DLL-> C#DLL
是吗?
我将在Google上搜索有关混合DLL的一些信息.
If I understand properly, you said I need to create a DLL which will do interface between my C++ Software and the C# DLL ?
Software --> Mixed DLL --> C# DLL
Is that right ?
I will search on google some informations about mixed DLL.