Callbacks aren't just used by the operating system though. Any object can require you to specify callback functions to handle events. There you go... you can sort of think of them as event handlers.
Main Topics
Browse All TopicsI am trying to learn more about dll files, and so I was looking at other people's code. Somewhere I saw this method declaration:
LRESULT __declspec(dllexport)__std
What do all those keywords mean?
I've seen LRESULT before as the return value in message handler functions although Im not sure exactly what it means.
__declspec(dllexport)__std
CALLBACK Ive seen before in Proc methods, but thats about all I know about it. Another question... what is proc short for?
Anyways, thanks in advance for the help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
true about the __declspec (dllexport) .. functions like this one can be seen outside from the dll (the oposite to this is __declspec (dllimport) .. these are functions from dll that will be used in your program)
that __stdcall has lot to do with passing arguments to function and cleaning up after return. see http://msdn.microsoft.com/
S.
huh .. havent read it all so few more answers:
LRESULT is just long integer number. nothing more.
for CALLBACK i found:
#define CALLBACK PASCAL
#define PASCAL __stdcall
no need to say more :)
this proc looks much like handler for keyboard hook. hooks are mechanisms that keep an eye on system and when something interesting (in your case keyboard hit) happens they invoke proper handler. good example are accelerators. when you press some key sequence an action starts. the hook looks after specified combination of keys and if the combination matches one it knows it invokes proper action. another good example is mouse-meter, application measuring how far have you moved your mouse. the hook catches every mouse move and before it sends it further it adds the distance of the last move to some global distance variable.
if you want to know more on hooks, look here http://msdn.microsoft.com/
S.
And for your last question which hasn't yet been answered:
Proc is simply short for procedure, which more or less means function. There are some variations in meaning; Pascal, IIRC, only calls functions without return value procedures, but as you can see in your example, in a Windows context procedures may very well return a value. Don't let it confuse you, it's really just another name for a function! :)
well, there is a difference.
a function is a term borrowed from mathematics and is supposed to be a function that compute some result and return
that result. Ideally a function is not supposed to have side-effects so if you call a function with a given set of arguments
it should return the same result every time regardless of other context and without modifying the external context in any way (no input/output for example).
A procedure is a prescription of something to do or how to do it so a procedure is simply a set of actions combined together. Specifically a procedure will have side effects in that it modifies context in some way (it does I/O, it changes
global variables etc etc).
In C and C++ a function may very well have side effects and so the distinction between function and procedure is blurred and when you also take into account that a C or C++ function which has void as return type really is
a procedure the distinction has completely vanished. In C and C++ we may still refer to such functions as procedures though
__stdcall is a calling convention. It is the calling convention used by all the Win32 functions. In practice this means that it is a "safe" calling convention since any programming language running under Win32 must support it in order
to being able to call Win32 functions. Thus, all languages (MS C and C++, VB, Delphi, Borland C and C++, fortran etc etc they all support this calling convention).
Because all languages support that calling convention it is "safe" to export functions as __stdcall since the function can then be called from any language. It is therefore a good thing to write your DLL so that all functions exported from the DLL is defined as __stdcall.
However, __stdcall cannot handle functions with variable number of arguments (printf etc) so those functions must be declared as __cdecl. For this reason you will find that some (1 or 2 I think) Win32 functions are declared as __cdecl and thus cannot be used by any language other than those that can support __cdecl (C, C++ - both MS and Borland - and Delphi and VB to name some that can handle __cdecl). __stdcall is therefore the preferred calling
convention for DLL functions while __cdecl is only used for those functions which must be __cdecl (functions
with variable number of arguments).
LRESULT and CALLBACK are not keywords, they are simply macros defined as skypalae said. LRESULT
is simply a macro that is replaced by 'int' by the compiler so anywhere you see LRESULT you can mentally
replace that with an 'int' type. However, there are reasons why using such a macro or typedef is a good
thing. For one thing, if they later decided to move on to 64 bit integer for all LRESULT values they can easily
do that by simply replacing one macro instead of replacing a zillion odd places where the type is used in code.
__declspec is a keyword and it is a Microsoft specific keyword (all C++ standard keywords are such that
they do not start with underscore) and it is used when declaring functions or variables in a DLL. If a function or
variable is defined as declspec(dllexport) then the function or variable will be exported from the DLL and you can link to the function from another program.
A callback is simply a function that someone will callback. There are several reasons why that is useful. For example if you call a function and want that function to do something. If this function is very generic there might
be things in this function that the function itself don't know how to handle, instead it simply calls a function back
to you to let you handle it.
Consider qsort, here is a declaration of qsort function:
void qsort(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *));
This function can sort any array of any size and any type in any way you want.
Sounds incredible? Well, it's true. The keypoints ar ethese.
1. It has a void pointer to the array, a void pointer can be used to point to anything - any array of any type.
2. It has two separate size variables, one with count of how many elements to sort and one with the
size of each element, so to sort integers you specify sizeof(int) as the size argument while if you instead
want to sort an array of double you specify sizeof(double) as the size argument.
3. It has a callback function to compare two elements. This is the real clue that makes the function
truly generic.
i) The callback function can compare any type of values. It gets a pointer to the two elements and must
return a negative value if the first element comes first in the sort order compared to the second. It must return a positive value if the two elements are in wrong sort order and it must return 0 if the two elements are identical.
Here's how you can sort an array of N integers in increasing order:
int compare_int_increasing(con
{ return *(const int *)a - *(const int *)b; }
qsort(arr, N, sizeof(int), compare_int_increasing);
Here's how you can sort them in decreasing order:
int compare_int_decreasing(con
{ return *(const int *)b - *(const int *)a; }
qsort(arr, N, sizeof(int), compare_int_decreasing);
You can sort doubles in increasing order using this function:
int compare_double_increasing(
{
if (*(const double *)a < *(const double *)b)
return -1;
if (*(const double *)a > *(const double *)b)
return 1;
return 0;
}
You can sort string using this function:
int compare_strings_increasing
{ return strcmp((const char *)a, (const char *)b); }
and so on and so on.
Similarly, callbacks can be used to trigger when some condition arise. For example in Win32 you can
use ReadFileEx to read a file and specify a callback function to be called when the data has been read into
the buffer. This way you don't have to wait for the job to finish but you just start the read and move on to
work on something else. When the data has been read in that function is called and it can flag your other
code to process the data etc. This is done through a callback function which then is called by the OS to
notify your program that some condition (in this case that data has been transferred) has occurred.
Hope this explains.
Alf
Business Accounts
Answer for Membership
by: smitty1276Posted on 2003-08-19 at 23:26:28ID: 9186146
Some of this I copied straight outta MSDN.
---------- ---------- ---------- ---------- ---------- ---------- -------- call
callback function: A function that receives messages from the operating system. Callback functions are application-defined.
CALLBACK Calling convention for callback functions.
LRESULT A 32-bit value returned from a window procedure or callback function.
A callback function is a function that you tell an "object" (usually) to call when an event occurs. In windows programming you have a callback function that windows calls everytime any message is sent to a window. In GLUT (if your into game programming), you pass the address of a display function, which it will call for you every time it wants to display the frame on screen. The idea of a callback function is that you get to control what it does, but it will be called everytime it meets some condition, depending on the situation (usually sometime of event or message).
--------------------------
__declspec(dllexport)__std
Extended attribute syntax uses the __declspec keyword to qualify extended storage-class information.
The dllexport and dllimport storage-class attributes are Microsoft-specific extensions to the C and C++ languages. They enable you to export and import functions, data, and objects to and from a DLL