How to load unmanaged library with P/Invoke?

So i have one old unmanaged library dll/tlb. I want to use it in .net 4.0 program. I have basicly no idea how to do this, so if u can provide me with some tutorial or even better example would be great. i was looking at this: pInvoke, .net 4 vs 3.5 but i can't figure anything out. I also checked this out but i don't know what should i be using so it would be working.

Thank u all for the help...


You add a reference to your library by right clicking the references folder in the solution explorer.

After that in the dialog box that appears you select the COM tab and the Browse, and find your DLL.

The if you want to acces different methods take a look at this example:

public static extern int MessageBox(int h, string m, string c, int type);

Where the dll between the square braces is your DLL and the extern keyword allows you to specify you are using the method from an external library.

For more reference please read:

Need Your Help

Validator will not accept null value

c# entity-framework

I am using ASP.NET MVC4 with C#. Visual Studio created some models based off a database I already created. One of the columns in the database was set to non null. I have since went back to the da...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.