Question

What do the modifiers in this method declaration mean?

Asked by: lwinkenb

I 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)__stdcall  CALLBACK KeyboardProc(parameters)

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)__stdcall has me pretty confused

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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-08-19 at 22:40:48ID20714566
Topic

C++ Programming Language

Participating Experts
4
Points
250
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. __declspec( dllexport ) with template
    I write a program that contains class and struct , the class is a template class , when I export my class and struct as dllexports , I get an warning that I can't shake , the warning go away if I declare T* t as public data , this is the code and the explanation , the warning...
  2. DLLEXPORT name decoration and varargs
    What is the name decoration applied to a function that such as: #define DLLEXPORT __declspec(dllexport) #define STDCALL __stdcall typedef unsigned char text; typedef unsigned short ub2; typedef short sb2; typedef unsigned long ub4; typedef ...
  3. __declspec( dllexport ) problem
    I have 2 questions, but I'll ask the first in this one! I'm trying to export a dll function using the following syntax: char* __declspec( dllexport ) myfunc(); however when I compile I get the following error: error C2059: syntax error : 'type' I then tried doing this: ...
  4. DllExport & DllImport
    Hi, I have an application, which uses around 6-7 OCX controls. The OCX controls are fairly independent of each other. There are no 3rd party controls (we have developed all the OCX controls). Each OCX control and the main application uses a dll (called option.dll and has bee...
  5. __stdcall __cdecl  __declspec ...
    I want to get a handle on these win32 stuff. I understand that in stdcall the function clean up the stack before returning. cdecl the caller clean up the stack? what about the declspec and the rest? Some references to some site would help greatly. Thanx

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: smitty1276Posted on 2003-08-19 at 23:26:28ID: 9186146

Some of this I copied straight outta MSDN.

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)__stdcall

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

 

by: smitty1276Posted on 2003-08-19 at 23:27:41ID: 9186156

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.

 

by: skypalaePosted on 2003-08-20 at 01:16:18ID: 9186516

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/library/default.asp?url=/library/en-us/vccelng/htm/msmod_7.asp to know more. and don't get confused with it .. most of the time you'll not need it.

S.

 

by: skypalaePosted on 2003-08-20 at 01:36:43ID: 9186621

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/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks.asp

S.

 

by: chofreitherPosted on 2003-08-20 at 02:39:12ID: 9186874

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! :)

 

by: SaltePosted on 2003-08-20 at 03:59:26ID: 9187134

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(const void * a, const void * b)
{ 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(const void * a, const void * b)
{ 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(const void * a, const void * b)
{
   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(const void * a, const void * b)
{ 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

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...