Reputation: 11090
I am iporting a method from an external dll and have the following code:
[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. The CreateGui method has been declared public and static within the dll? Anybody any ideas?
Thanks.
Upvotes: 0
Views: 240
Reputation: 47038
If the method returns a TabPage it is a .NET method, hence it is a .NET Assembly. Then you should not import it with DllImport, but add the dll as a reference in your project.
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
.
Upvotes: 2