PDA

Click to See Complete Forum and Search --> : [RESOLVED] API in VB.NET


Paul M
Dec 10th, 2007, 05:15 PM
Hi MSVB Team i was just wondering what you all thought about the use of API in almost any .NET language but VB.NET more specifically. I find that a lot of stuff can be done with the .NET library instead of using API, is it generally best to use the .NET libraries when it is applicable to do so?

Thanks Paul M

PaulYuk_MS
Dec 10th, 2007, 07:06 PM
Hi - could you please clarify what you mean by API vs. .NET library (using some examples)? Are you specifically refering to API features in the VB runtime like MsgBox(), CInt, Left(), etc?

Paul M
Dec 11th, 2007, 01:38 AM
Sorry about that i was in a rush to get to work :)

Anyway i mean like in general would it be better especially performance wise to use the appropriate .NET library over API?

For example checking if a user has administrator privileges, would it be better to use the System.Principal library or to use API directly to determine this?

Sorry it is a very broad question but would you suggest using the .NET libraries over API when it is possible to do so?

Paul M
Dec 11th, 2007, 01:40 AM
Sorry the System.Security.Prinicpal library.

jmcilhinney
Dec 11th, 2007, 01:55 AM
By "API" I'm guessing Paul means the Windows API via PInvoke, yes?

Paul M
Dec 11th, 2007, 02:03 AM
By "API" I'm guessing Paul means the Windows API via PInvoke, yes?

Yes :)

jaredp110680
Dec 11th, 2007, 11:21 AM
In general if the API is available via .Net I would choose that over a PInvoke version. PInvoke is complex and has a lot of dark corners. When a .Net wrapper is produced that exposes these API's, generally the author has done the work to get it right and it should be easier to consume.

Liquid Metal
Dec 11th, 2007, 01:01 PM
It would be a wrapper and would add an extra layer that might be a bit slower.

funkyonex
Dec 11th, 2007, 01:50 PM
In general I always prefer the .NET managed libraries over the Windows API. They are usually much cleaner, easier to use and faster to program. Only when they do not provide the functionality I need then I drop down to call the API directly. In the types of .NET applications I have built over the years (information systems) I have never noticed a performance penalty for using managed wrappers. My performance concerns lay elsewhere -- like database query times and network serialization ;-). It all depends on the types of applications you are writing.

HTH,
-B

wossname
Dec 11th, 2007, 02:26 PM
Every Operating System API call you use binds you to that particular OS more tightly. That is pretty much the reverse of what .net is all about - cross platform working.

Paul M
Dec 11th, 2007, 05:09 PM
Thanks guys, i always use the .NET libraries over API and sounds like i will continue :D

jmcilhinney
Dec 11th, 2007, 05:12 PM
The entire .NET Framework library is really just a wrapper. If you're not going to use it all the time you can then why use it at all? Assume that you should always use a managed type and/or member if one is available unless you have a specific reason for doing otherwise.