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. http://codenition.blogspot.com/2010/05/pinvokestackimbalance-in-net-40i-beg.html

Thank u all for the help...

Answers


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:

[DllImport("User32.dll")]
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: http://msdn.microsoft.com/en-us/library/e59b22c5%28v=vs.80%29.aspx


Need Your Help

Validator will not accept null value

c# asp.net entity-framework asp.net-mvc-4

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.