tags:

views:

84

answers:

1

From version to version of .NET the more function that's equal to P/Invoke is added to .NET

Now there are 2 questions in my mind.

1) Which one is prefer over the other in term of speed, normally I use .Net function but in tight loop I don't really know which one is going to be faster.

2) Is there any website that provide the list of counter-parts?

+4  A: 

1) If there is a .NET function you should, of course, use it - unless you have a really good reason not to.

2) Yes, there is a page that maps Win32 API functions to .NET methods, though it's quite old - it applies to .NET 1.1. See http://msdn.microsoft.com/en-us/library/aa302340.aspx

Edit: There is no newer list that I'm aware of, but one trick you could try is opening the .NET framework assemblies (like mscorlib, System, etc.) in Reflector and searching for the Win32 method name. If the assembly invokes it internally you should be able to find it this way and then find where it's referenced to trace it to a public method that you can call, if there is any. If there isn't, at least you can copy the P/Invoke signature without having to figure it out.

Evgeny
Is there any newer ones out there? I came across that but as you say it's old.
Jonathan Shepherd
pinvoke.net lists managed equivalents for many Win32 functions
Ben Voigt
As far as Performance in a tight loop goes, If speed is absolutely critical there are many cases where using PInvoke in .NET will actually make it MUCH slower than either the .NET methods or writing a Win32 app. (Sometimes its fastest to write a Win32 app just for that tight loop, then parse the logs in your .Net app)
David Heise