|
-
Dec 12th, 2007, 02:47 PM
#1
Some general questions about API
Hi Guys,
I know I know, another newbie asking about APIs, sorry!
I've just been noticing that a lot of the things I want to do in my apps recently havent been possible through the .NET framework directly and needed me to use APIs... which im not quite sure how to do so I've usually just tried copying examples and screwing them up trying to change them to suit my needs 
So basically I was just wondering - 1. what is the correct way in VB.NET to 'call' (or whatever the correct word is) an API? I've noticed examples use DLLImport or something but then there is usually a lot more 'strange' (to me) code required when actually trying to use the API functions.
2. Why do we use APIs? I mean if we can code something using an API why couldnt it just be a method in VB.NET or whatever language? Is it PURELY because it would take so long and make the framework so large if it included every possible function in Windows?
3. I know the APIs are stored in DLL files so are they just kinda like a definition of what arguements the API function accepts etc? and if so why do you have to type so much code to use them? If all the data is in these DLL files why is not just a case of importing the DLL and then using the function or method like any other in the framework?
4. How do you learn how to use an API or learn that it exists? is it purely just a case of searching the internet?
Sorry if these are daft questions and I did try to research this before posting but couldnt find precise answers to these questions (that made sense to me anyway)
-
Dec 12th, 2007, 03:15 PM
#2
Re: Some general questions about API
2. API's are used as they are already written, and more importantly already tested to ensure they work properly and safely.
There are many cases where code you write uses API's, even if you aren't aware of it (things like showing a MessageBox are actually done by API's, what you are calling is just a wrapper around it).
You are right that there are too many API's to add them all to a language - especially as in many cases they will not be used, or have too many possible variations of usage to be able to provide a usable wrapper. Instead, just the relatively 'popular' ones are added, and you add more as you need them.
If you find that you are repeatedly using an API in a similar way, you can create your own wrapper (in a class) for it.
3. A DLL is a compiled program, just like your own projects, and the code is inside them.
The 'data' is not included in these files, as there are so many different ways in which they can be used - normally interacting with other items in Windows, which in many cases didn't exist (and perhaps weren't even thought of) until after the original functions were created.
4. There are various sources, one is the official documentation (unfortunately based on C style languages):
http://msdn2.microsoft.com/en-us/library/Aa383686.aspx
There are also various programs (such as this one) which provide organised (and searchable) lists, including examples. Unfortunately they tend to have a limited number of API's in them, but that is usually enough.
-
Dec 12th, 2007, 04:04 PM
#3
Re: Some general questions about API
OK thanks for the info, I did have a look on msdn but it didnt seem like there were as many APIs as I thought there would be so I figured I hadnt found the right bit...
Any advice on my first question? How to actually use APIs in vb.net? I realise that each API is different so its not like you can give me an example that I could just use with anything but I'd just like to know some basic rules so that I dont have to find someone else's code and copy it every single time I want to use an API...
-
Dec 12th, 2007, 04:34 PM
#4
Re: Some general questions about API
I don't use VB.Net enough to comment on that part.
As to coping code examples, I'm afraid that is basically the best option.. you can get information from places like MSDN (note that each category listed there can contain hundreds of API's!) about what the parameters mean and what constants to use etc, but it can take a lot of work to build up to the equivalent of an example that somebody else has already created.
Once you have got an example, store it somewhere so that you can easily find it again - the API Viewer I linked to before already contains some VB.Net examples as well as a place to store your own code/notes for each API (and it also tells you what the parameters etc mean).
-
Dec 12th, 2007, 05:42 PM
#5
Re: Some general questions about API
Yeah I'm just looking at that now thanks again for the answers
Anyone who uses vb.net more fancy explaining to me some of the basics of how to incorporate the use of an API call into my applications?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|