Click to See Complete Forum and Search --> : What's the diff. between API func and API sub?


mikledet
December 22nd, 2002, 05:34 PM
Hi All,

Through the API viewer, one can see - API function decleration, and API sub's declerations...
In VB I found this on MSDN about the differnace between function and sub routine:


quote:
--------------------------------------------------------------------------------
A Sub procedure differs from a Function procedure in that a Sub procedure cannot be called by using its name within an expression. A call to a Sub is a stand-alone statement. Also, a Sub does not return a value in its name as does a function. However, like a Function, a Sub can modify the values of any variables passed to it.
--------------------------------------------------------------------------------


Now, the API's are written in C, are there sub routines in C??


Thanks in advance

Dani.

stober
December 22nd, 2002, 08:36 PM
You have to check the API function's return value to determine whether it is a VB-style Function or Sub. If the API returns "void", then it is a Sub. If it return something else, such as BOOL, then it is a Function.

Amn
December 23rd, 2002, 06:46 AM
Now, the API's are written in C, are there sub routines in C??


In C++ and WinAPI sense, there is no such thing as subroutine. WinAPI is basically a BIG bunch of exported pieces of code, identified by the jump-address entry when they are loaded into memory. Jump-address is a location in memory, that CPU executes until a 'ret' instruction is hit which tells CPU to return from that subroutine/function/piece of code. So basically think of those as sequences of instructions, each starting with extracting parameters, and ending with a return instruction (ret).

C++ only has functions, which are mapped into those addresses, when not loaded dynamically via LoadLibrary and GetProcAddress.

But stober is right, VB for instance, differentiates subroutines from functions, as it is so by nature. And so it does for its WinAPI mapped libraries, so that programmers feel confident in their understanding of the language and dont need to think of jump-adresses etc. VB is supposed to be easy and fast to code, and so it is :)