在C#中使用MFC C Dll [英] use of MFC C Dll in C#
本文介绍了在C#中使用MFC C Dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有一个基于GUI的c代码.
我想将其转换为dll,然后使用此dll
在C#中.
我已经在c#中使用了c dll,但是该dll的代码不是基于GUI的.
通过将所有代码简单地编写到c中的类文件中并使用__declspec内部的函数,我可以创建DLL并在c#中使用
但是我的问题是如何在创建c的dll中创建基于gui的代码,然后使用
在C#中.
如何在c#plz帮助中使用MFC C dll
在此先感谢
Saima
Hi All
i have a code of c which is GUI based .
I want to convert it into the dll and then use this dll
in c#.
I already use c dll in c# but the code of that dll is not GUI based .
By simply writing that all code in a class file in c and using function inside __declspec I CREATE THE DLL and use in c#
But my problem is how to create gui based code in creating dll of c and then use
in c#.
How use MFC C dll in c# plz Help
Thanks in advance
Saima
推荐答案
原则上可以做到,但实际上没有任何实际意义.您最好编写纯.NET UI并使用C ++中的一些语义代码,也许根本不用MFC.
无论如何,如果要在.NET汇编中使用C ++代码,则只有两种方法.
第一种方法:使用P/Invoke.您可以学习它:
http://en.wikipedia.org/wiki/P/Invoke [ http://msdn.microsoft.com/en-us/library/Aa712982 [ ^ ].
此CodeProject文章也可能有用:基本P/调用 [
另请参见:
http://en.wikipedia.org/wiki/C%2B%2B/CLI [ ^ ],
http://www.ecma-international.org/publications/standards/Ecma-372.htm [^ ],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx [ ^ ].
—SA
In principle, you can do it, but it makes no practical sense, really. You better write pure .NET UI and use some semantic code from C++, perhaps without MFC at all.
Anyway, you if want to use C++ code in .NET assembly, there are just two approaches.
First approach: use P/Invoke. You can learn it:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/en-us/library/Aa712982[^].
This CodeProject article can also be useful: Essential P/Invoke[^].
Second approach is based on using C++/CLI. You can either re-write your C++ code into C++/CLI or create a mixed-mode (managed+unmanaged) project combining C++/CLI with your legacy C++ code. You can then wrap your C++ code in C++/CLI ("ref") classes or structures and make them public. You can reference such mixed-mode assembly just like a normal .NET assembly in your C# project.
See also:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[^].
—SA
这篇关于在C#中使用MFC C Dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文