看不到 DLL 中的方法...为什么?
看不到 DLL 中的方法...为什么?
我用 C# 开发了一个 DLL,
当我尝试调用它时,我得到:
System.EntryPointNotFoundException: Unable to find an entry point named:
这意味着 DLL 不会导出 DLL 中可见的任何方法。 Dumpbin 也不显示任何方法:
dumpbin.exe -exports ActiveXTest.dll 文件 ActiveXTest.dll 的转储 文件类型:DLL 概括 2000.reloc 2000.rsrc 2000 .text
出了什么问题???
DLL 看起来不错..根据文档:
namespace Kosmala.Michal.ActiveXTest
public static void setHooks()
{
....
}
这是我的调用方式:
namespace IWFHotkeyStarter
{
class Program
{
[DllImport("D:\\work\\iwf\\_ctrl-tab-modless_dlg_testing\\activex\\VSProjects\\AcriveXSourceCode\\bin\\Debug\\ActiveXTest.dll")]
public extern static void setHooks();
static void Main(string[] args)
{
Program p = new Program();
p.run();
}
private void run(){
Console.WriteLine("run<<");
setHooks();
Console.WriteLine("run>>");
}
}
}
请帮忙
Can't see methods in DLL... why?
I developed a DLL in C#
When I am trying to call it I get:
System.EntryPointNotFoundException: Unable to find an entry point named:
It means that DLL doens't export any methods visible from DLL. Dumpbin doesn't show any methods either:
dumpbin.exe -exports ActiveXTest.dll
Dump of file ActiveXTest.dll
File Type: DLL
Summary
2000 .reloc
2000 .rsrc
2000 .text
What's wrong????
The DLL looks ok.. according to documentation:
namespace Kosmala.Michal.ActiveXTest
public static void setHooks()
{
....
}
Here is how I call it:
namespace IWFHotkeyStarter
{
class Program
{
[DllImport("D:\\work\\iwf\\_ctrl-tab-modless_dlg_testing\\activex\\VSProjects\\AcriveXSourceCode\\bin\\Debug\\ActiveXTest.dll")]
public extern static void setHooks();
static void Main(string[] args)
{
Program p = new Program();
p.run();
}
private void run(){
Console.WriteLine("run<<");
setHooks();
Console.WriteLine("run>>");
}
}
}
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 DLL 是托管代码(用 C# 编写)。经典 DLL(例如 ActiveX 控件的容器)是非托管代码,并以另一种方式组织。
要在托管项目中使用托管 DLL,请添加对其的引用或在运行时加载它。
Your DLL is managed code (written in C#). Classic DLLs like containers of ActiveX controls are unmanaged code and organized in another way.
To use a managed DLL in a managed project, add a reference to it or load it at runtime.
正如 Mario 所说,.Net 程序集以不同的方式公开库和类,因此像 DumpBin 这样的工具不会显示任何内容 - 如果您想查看程序集内部,请给出 Reflector 尝试一下。
至于如何调用托管程序集,您已经显示的方法(DllImport) 用于互操作/调用非托管代码。要调用另一个托管程序集中的方法,您所需要做的就是添加程序集引用,您应该能够很好地看到该方法。
另一件需要注意的事情是,在 C# 中,所有方法都必须属于一个类,因此您的示例可能看起来更像这样:
使用方法:
As Mario states, .Net assemblies expose libraries and classes in a different way and so tools like DumpBin won't show anything - if you want to peek inside your assembly then give Reflector a try.
As for how to call your managed assembly, the method you have shown (DllImport) is used for interops / calling unmanaged code. To call a method in another managed assembly all you need to do is add an assembly reference and you should be able to see the method just fine.
Another thing to note that in C# all methods must belong to a class, so your example will probably look more like this:
Using the method:
如果您有一个接口,那么您尝试调用的 setHooks() 方法请确保它在接口中声明。
If you have an Interface then the setHooks() method you are trying to call make sure it is declared in the interface.