无法将MFC dll添加到C#代码中的引用 [英] Unable to add MFC dll to referece in c# code

查看:302
本文介绍了无法将MFC dll添加到C#代码中的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经在VC ++中用可用的cpp文件和头文件构建了MFC类型和Win32类型的项目,最后我在debug文件夹中得到了一个dll.

1)MFC dll->当我尝试在C#中添加Referece时,整个解决方案即将关闭.

2)Win32 dll->我无法注册该dll并添加对c#项目的引用.当我尝试注册该DLL时出现以下错误,即
dll已加载,但未找到DllRegisterServer入口点.

在Google中,我也没有任何适当的解决方案.
如果我在MFC和Win32项目中制作dll时缺少任何设置,您能帮我这个忙吗? :(

谢谢,
Satya

Hi,

I have build MFC type and Win32 type projects in VC++ with available cpp files and header files, finally i got one dlls in debug folder.

1) MFC dll--> When i am trying to add referece in c# entire solution is closing.

2) Win32 dll--> I am unable to register that dll and add reference to c# project. when i am trying to register that dll getting following error i.e.
dll was loaded, but the DllRegisterServer entry point was not found.

In google also i am not getting any proper solution.
can you help me on this, if i am missing any settings while making dll in MFC and Win32 projects. :(

Thanks,
Satya

推荐答案

萨蒂亚,

要将本机代码(非托管)dll与托管dll(C#dll/程序集等)一起使用,我们应该进行pInvoke或使用COM可调用包装器(CCW).

现在,当您创建MFC dll时,您应该已经有了一些GUI.然后,您应该创建MFC Activex控件,而不是MFC dll.然后只有您可以注册它并在C#中使用它

您的DLL无法注册,因为它没有导出regsvr32.dll进行注册所必需的DllRegisterServer方法.
Hi Satya,

To use a native code (un-managed) dll with managed dlls (C# dlls/assemblies etc..), we should go for pInvoke or use COM callable wrapper (CCW).

Now as you have created a MFC dll, you should be having some GUI. Then you should be creating MFC Activex control, rather than MFC dll. Then only you can register this and use it in C#

Your DLL can not be registered as it is not exporting DllRegisterServer method, which is required by regsvr32.dll to perform registration.


添加到.NET项目中的引用不仅仅是DLL.您只能引用任何可执行文件(顺便说一下,可以是DLL,EXE-没什么区别),前提是该文件是某个有效的.NET程序集的主要可执行模块.

您可以在.NET程序集中使用本机代码,但这到目前为止还不是那么简单.这样做的方法称为P/Invoke.如果只阅读这篇文章,您可以学到很多:
http://en.wikipedia.org/wiki/P/Invoke [ http://msdn.microsoft.com/en-us/library/Aa712982 [ ^ ].

这是有关以下主题的出色CodeProject文章:基本P/调用 [
最后,我真的怀疑您是否可以在.NET应用程序中使用MCF.使他们生活在一起并不容易,所以我认为这没有道理.自己看看吧.

—SA
The references you add to a .NET projects are not just DLLs. You can reference any executable file (by the way, it can be DLL, EXE — no difference) only if this is a main executable module of some valid .NET assembly.

You can use native code in your .NET assembly, but this by far not so simple. The method of doing it is called P/Invoke. You can learn a good deal of it if you read just this article:
http://en.wikipedia.org/wiki/P/Invoke[^].

For further information, please see: http://msdn.microsoft.com/en-us/library/Aa712982[^].

This is a good CodeProject article on the topic: Essential P/Invoke[^].

An alternative to P/Invoke is using C++/CLI language in combination with C++ in one project; which could be a "mixed-mode" project (managed+unmanaged). You can bind unmanaged API in C++, wrap it in C++/CLI "ref" classes and make them public. The output executable module of such project can be referenced as a regular .NET assembly by your .NET assemblies.

Finally, I really doubt you can use MCF in a .NET application. It is not easy to make them live together, so I don''t believe it makes sense. See by yourself though.

—SA


这篇关于无法将MFC dll添加到C#代码中的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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