简体   繁体   English

c#dllimport问题

[英]c# dllimport question

I am iporting a method from an external dll and have the following code: 我正在从外部dll导入方法,并具有以下代码:

[DllImport("test.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    public static extern TabPage CreateGUI();

and to call this: 并称之为:

tabControl1.TabPages.Add(CreateGUI());

I get the error saying that CreateGui cannot be located within the dll. 我收到错误,说CreateGui不能位于dll中。 The CreateGui method has been declared public and static within the dll? CreateGui方法是否已在dll中声明为公共且静态的? Anybody any ideas? 有人有什么想法吗?

Thanks. 谢谢。

If the method returns a TabPage it is a .NET method, hence it is a .NET Assembly. 如果该方法返回TabPage,则它是.NET方法,因此它是.NET程序集。 Then you should not import it with DllImport, but add the dll as a reference in your project. 然后你不应该用DllImport导入它,而是在项目中添加dll作为参考。

Edit: 编辑:
If you want to load a .NET Assembly dynamically you need to load it with Assembly.LoadFile and then find your types with Assembly.GetTypes . 如果你想动态加载.NET程序集,你需要加载它Assembly.LoadFile用,然后找到你的类型Assembly.GetTypes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM