What is this LRESULT CALLBACK

In

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

How come this type of declaration is alowed?
Like I mean for LRESULT CALLBACK
Isn't it like: datatype datatype
LRESULT is a typecast of a number, I think a long but I can't seem to find a source it to double check that.

A "callback" is a function pointer that is called everytime a certain condition is met. See here: http://www.cplusplus.com/reference/iostream/ios_base/register_callback/

EDIT: This: http://www.cplusplus.com/reference/iostream/ios_base/event/ suggests that "LRESULT" might be an enumeration, that would make it an integer.
Last edited on
Can you please explain this with a STANDARD and CLASSIC example(like using int, long or * etc)?
It would look kind of wierd since you assign this call back to the instance of your window as a data member (lpfnWndProc) instead of using the "ios_base::register_callback(...)" function; and I'm not going to rewrite that struct right now.

It's just the function that is called to process the messages from your running loop for that instance of a window.
My question is about the declaration!
This works for WinMain()...

 
int __stdcall WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)


and this for the Window Procedure...

 
long __stdcall fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)


An LRESULT is just a long. However, the above will only work for 32 bit OS. The calling conventions are different for 64 bit Win. So your best bet by far if you are contemplating Win SDK development (or anything else, for that matter), is to stick to the defines and typedefs in the Windows headers. You really don't have much choice in this.

The thing I find bizarre is that just about all these typedefs used in windows (at least for 32 bit) are just ints of one kind or another, e.g., int, unsigned int. However, we have to deal with HFONT, HBRUSH, LRESULT HINSTANCE, HDC, HNENU, etc, ad infinitum. In all my years of coding I can't remember one time where this sort of thing has saved me from inadvertantly passing the wrong kind of object to a function.

For this reason I find coding in PowerBASIC to be rewarding and more hassle free. Take for example a WM_PAINT handler involving a 'HDC', which is just really an opaque pointer 32 bits in size (for 32 bit OS). In C or C++ you have this...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
typedef struct    WindowsEventArguments
{
 HWND             hWnd;
 WPARAM           wParam;
 LPARAM           lParam;
 HINSTANCE        hIns;
}WndEventArgs, *lpWndEventArgs;


long fnWndProc_OnPaint(lpWndEventArgs Wea)
{
 char szBuffer[]="Hello, World!";
 PAINTSTRUCT ps;
 HDC hDC;

 hDC=BeginPaint(Wea->hWnd,&ps);
 TextOut(hDC,0,0,szBuffer,strlen(szBuffer));
 EndPaint(Wea->hWnd,&ps);

 return 0;
}


And in PowerBASIC one just uses the primitive data type ( long - 32 bits signed) for everything, here HDC...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Type WndEventArgs
  wParam As Long
  lParam As Long
  hWnd   As Dword
  hInst  As Dword
End Type

Function fnWndProc_OnPaint(wea As WndEventArgs) As Long
  Local szBuffer As Asciiz*16
  Local ps As PAINTSTRUCT     
  Local hDC As Long           
                              
  hDC=BeginPaint(wea.hWnd,ps) 
  szBuffer="Hello, World!"
  TextOut(hDC,0,0,szBuffer,Len(szBuffer))
  EndPaint(wea.hWnd,ps)

  fnWndProc_OnPaint=0
End Function


Just easier.

@freddie: you correct
closed account (zb0S216C)
CALLBACK is an alias for __stdcall (according to VC++). LRESULT, on the other hand, is an alias for long (again, according to VC++).

So, when you translate the two, you get:

long __stdcall WndProc( ... )

Wazzak
Last edited on
Plz tell me which books did u learn frm?
My books dnt illustrate anything
They jus say: wtf
You can read windows headers included with your compiler to figure out.
MSDN ftw...

its microsoft-specific stuff - calling conventions etc...
wats MSDN ftw?
MSDN - Microsoft Developer Network.

If you want to learn Windows GUI SDK API Style programming, I'd highly recommend Charles Petzold's "Programming Windows". Its a very large book and describes in detail all the variable types, macros, typedefs, calling conventions, etc., involved in Windows Programming.
@freddie1: I know wats MSDN, and I do have the Petzold book(Thanx for that)
I dnt know wats "ftw"
"for the win"?

An enthusiastic emphasis to the end of a comment, message, or post. Sometimes genuine, but often sarcastic.

Originated from the game show Hollywood Squares where the result of the player's response is expected to win the game.
Last edited on
Topic archived. No new replies allowed.