如何在C#中访问MFC常规dll导出函数? [英] How to access MFC regular dll Exported functions in C#?
问题描述
问题定义:
我们有MFC常规dll槽,我们导出了5个函数.
问题是如何从C#应用程序访问常规MFC dll导出的功能?
输入:
1.最初MFC dll是在Visual Studio 6.0下开发和构建的.
2.它的def文件包含5个导出函数的列表. (不属于任何班级)
3.在启用了/Clr选项的情况下,我能够在VS 2005 Studio上成功构建此dll.
4.如果我尝试在C#应用程序中添加.tlb文件的引用,则会出现错误:无效的程序集或com组件.
问题是
我在这里做错了什么?在C#应用程序中还将转换后的dll(启用了/clr)添加为参考也不会向我显示导出函数的列表.
从C#应用程序访问常规MFC dll(在共享Dll中使用MFC)的正确方法是什么?
新增信息:
我的dll中有5个导出函数,而不是任何类的成员,并按如下所示导出:
__declspec(dllexport)long WINAPI Functio1(float * pf,float * pf1,
float * pf2,float * pf3,长型)
Problem Definition:
We are having MFC regular dll trough which we exported 5 functions.
Question is how to access regular MFC dll exported functions from C# application?
Input:
1. Originally MFC dll was developed and built under Visual Studio 6.0
2. It''s having def file containing list of 5 exported functions. (Not under any class)
3. I was able to built this dll successfully on VS 2005 studio with /Clr option enabled.
4. If i tried to add reference of .tlb file in C# application, it''s giving me error: Not valid assembly or com component.
Question is,
What I am doing wrong here? Adding converted dll (with /clr enabled) also as reference in C# application does not show me list of exported functions.
What is the proper way of accessing regular MFC dll (Use MFC in shared Dll) from C# application?
Newly Added Information:
I am having 5 exported functions in my dll, not member of any class and exported as follows:
__declspec(dllexport)long WINAPI Functio1(float *pf, float *pf1,
float *pf2, float *pf3, long Size)
推荐答案
我认为您需要使用的是System.Runtime.InteropServices
命名空间.
I think what you need to do is use theSystem.Runtime.InteropServices
namespace.
您可以使用P/Invoke从C#使用普通的本机dll.使用extern "C"
导出C ++函数以防止C ++名称混乱,然后按如下所示将它们导入C#项目中:
You can use a normal native dll from C# using P/Invoke. Export your C++ functions usingextern "C"
to prevent C++ name mangling, then import them in your C# project like this:
[DllImport( "user32.dll" )]
public static extern IntPtr SendMessage(
IntPtr hWnd,
UInt32 msg,
IntPtr wParam,
IntPtr lParam );
网上有很多有关P/Invoke的信息.该站点将为您提供大量示例:
http://www.pinvoke.net/ [ ^ ]
尼克
There''s plenty of info on P/Invoke on the net. This site will give you plenty of examples:
http://www.pinvoke.net/[^]
Nick
感谢你们两个的回答,能否请您告诉我如何使用C ++/CLI包装器实现相同的目的?
由于某些良好的原因,我不想使用P/Invoke.预先感谢.
Thanks to both of you for your answers, can you please tell me How I can achieve the same using C++/CLI wrapper?
For some good reasons I don''t want to go with P/Invoke. Thanks in advance.
这篇关于如何在C#中访问MFC常规dll导出函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!