How are APIs made, and how do they work with programming languages?
#1 Members - Reputation: 108
Posted 11 May 2012 - 03:00 AM
Who, or specifically how and where, are the APIs written, from what, to what, and how can they work with languages till the very end of code compilation/assembling?
Are they libraries with specific low-level functions that are written from any other language that perform low-level calls on .dll files to change aspects, such as Window display, etc.?
Do they go lower-level than Windows or the OS itself's natural dependency, or that depends?
For example, does SDL perform low-level functions beneath the Windows API, or just for its own client window?
Very confused with this, and giving some suggestions. No harm, no foul, and not trolling either.
#2 Members - Reputation: 952
Posted 11 May 2012 - 03:47 AM
Edited by TheUnbeliever, 11 May 2012 - 03:48 AM.
#4 Staff - Reputation: 8926
Posted 12 May 2012 - 01:15 AM
An API is just a library of code, and in that respect it's not really special or different than any other piece of software other than the fact that it may (but may not be!) be at a lower level than you would normally want to work at when writing an application. An API generally provides an interface or abstraction of a lower level system, whether this is another software library or working more directly with a piece of hardware.Who, or specifically how and where, are the APIs written, from what, to what
The programmer creates source-code just like you do yourself when writing a program, and then compile it just like you would -- although they will probably choose to produce a dll or other library file format rather than an executable -- this is just a different compiler option, and might in some cases require some specific coding styles.
SDL uses the Windows API (this is what TheUnbeliever means by "written on top of"), and other lower level APIs.For example, does SDL perform low-level functions beneath the Windows API
Rather than needing to know all the Windows API calls necessary to set up and control a window, you use the simpler SDL functions. This is what I mean when I say they provide an "interface".
SDL can also be used on operating systems other than Windows, and on those other systems SDL will use an API appropriate to that OS rather than the Windows API -- but as a programmer using SDL you don't need to know or care about that difference, you just call the same SDL functions. This is what I mean when I say an API provides an "abstraction".
Is that any clearer?
- Jason Astle-Adams.
From my blog: 20 ways to advertise your game | What next? Intermediate to advanced C++
How to make games WITHOUT programming | 4 reasons you aren't a successful indie developer
#5 Members - Reputation: 108
Posted 13 May 2012 - 09:41 PM
Very clear.
But can I ask something else?
How, or specifically under what circumstances of implementation, are lower level functions, codes, etc. applied?
I am a bit cloudy there.
Like how SDL works with WinAPI ... how does it do it? I mean to add, I understand VERY little Windows API programming, but what I don't understand is how it exactly works beneath just typing in things, and I really want to know how, but reading the header files is like Hieroglyphics, and doesn't help me.
I just feel that by knowing this it would help me get the bigger picture of API use, specifically the only one I have managed to use correctly and have succeeded in(SDL).
This is, to also add, why I feel that learning some lower-level codes, how they work, how they work with each other, and how they work in general, would help me a bunch as I finally start stepping up in programming, designing and completing my first ever game program, etc.
So if you could wire this together in some sense, any sense, I'd appreciate your efforts.
Edited by Willy The Vinyl Frog, 13 May 2012 - 09:44 PM.
#6 Crossbones+ - Reputation: 1016
Posted 13 May 2012 - 11:48 PM
programWindow myWindow(800, 600, 32);Passing in just those parameters.
But if you want to do it without the API you will have to call several different functions to set up your window, say one setting the width and height, one setting what resolution you want (24bit, 32bit, etc) and then you may have to deal with various window handles.
The API may also take care of catching window events for you, and all you do is ask for them, while without the API you have to register to receive the events, then make sure to check for them.
#7 Members - Reputation: 108
Posted 14 May 2012 - 12:21 AM
A simple API function call (or in this case a constructor) to initialize a window may be:
programWindow myWindow(800, 600, 32);Passing in just those parameters.
I understand, but what do you mean by "(or in this case a constructor)"?
Being very unfriendly with C++'s OOP, I can't say for sure that I get that.
Although most of what you say clarifies it, I still wish to understand how exactly it does it for Windows API.
#8 Staff - Reputation: 8926
Posted 14 May 2012 - 12:55 AM
- Jason Astle-Adams.
From my blog: 20 ways to advertise your game | What next? Intermediate to advanced C++
How to make games WITHOUT programming | 4 reasons you aren't a successful indie developer
#10 Members - Reputation: 442
Posted 14 May 2012 - 10:55 AM
Thinking of common web API's, Google charts is a simple example, they have elaborate functions to do cool stuff internally that you don't need to know about, you simply connect and pass in the information you want it to perform cool actions on, and it gives you back the result of the information you passed in, in a dynamic or interactive format.
Jquery for example is simply javascript that you access from other javascript files. Instead of writing your own function to make an element draggable, you simply call a function premade in jquery(plain javascript) which takes care of detecting mouse click, monitoring drag coordinates on an element, etc. you just worry about what element you want to be draggable.






