Understanding callback

K

kid joe

Hello,

I have seen the WndProc prototyped two ways,

LONG WINAPI WndProc ( .... );
and
LRESULT CALLBACK WndProc ( .... );

Are these functionally equivalent?
What are WINAPI and CALLBACK defined as?
Why are there two ways to go about this?

Thanks.


--

.--------------------.
| |
| Good Evening.... | .--.--.
| | .; .;|;. ;.
`-------------. ,---' .;_;' `;_;.
\| ; ;' `; ;
\ ;;'.--.___.--.`;;
;-( o )=3D( o )-;
( `--' | `--' )
\| . . |/
........... . .:::::. . .______
/ . '---` . '\
.' `. .' \
| ____,.- . | `.....' | _______ |
| ,-' \ /|\'' \.-- |
| / \.'\ /,'. \. - |
| /| ` `\ / \ |
| ,/ _ '/ '\ |
,-' ,-. |o '
/ '| | | | \
/ ,/| |o | \ `
| .' | |.' |. \ \
________/ .'____|________________________||__`. `__________
( \ ) / )
'-. '-. ( .-` .-`
'-. .-'--.__. .-.__.--`-. .-`
'-..' \--' : ~`:=3D,`- `..-`
\ .. \\ |`-'|`-, /
\\\\\\\) | |`-'/.'/
\)\)\\ `-' `-'
`
 
K

Keith Thompson

kid joe said:
I have seen the WndProc prototyped two ways,

LONG WINAPI WndProc ( .... );
and
LRESULT CALLBACK WndProc ( .... );

Are these functionally equivalent?
What are WINAPI and CALLBACK defined as?
Why are there two ways to go about this?

These are specific to Windows. You'll get much better information
if you post to comp.os.ms-windows.programmer.win32.

And please use a shorter signature.
 
J

jacob navia

kid said:
Hello,

I have seen the WndProc prototyped two ways,

LONG WINAPI WndProc ( .... );
and
LRESULT CALLBACK WndProc ( .... );

Are these functionally equivalent?

Under 32 bit windows they are equivalent.
Under 64 bit windows they are not since LRESULT
is a 64 bit type and LONG is a 32 bit type...

What are WINAPI and CALLBACK defined as?

WINAPI is _stdcall in 32 Bit windows
CALLBACK is also defined as _stdcall.

Under 64 bit windows _stdcall doesn't exist
so both definitions are equivalent too,
probably defined as nothing.
 
K

kid joe

Under 32 bit windows they are equivalent.
Under 64 bit windows they are not since LRESULT
is a 64 bit type and LONG is a 32 bit type...



WINAPI is _stdcall in 32 Bit windows
CALLBACK is also defined as _stdcall.

Under 64 bit windows _stdcall doesn't exist
so both definitions are equivalent too,
probably defined as nothing.

Thanks a lot for the info.

I guess the only remaining question is, why are there these two different
prototypes for the same function, even if they're functionally equivalent?

Joe


--
.--------------------.
| |
| Good Evening.... | .--.--.
| | .; .;|;. ;.
`-------------. ,---' .;_;' `;_;.
\| ; ;' `; ;
\ ;;'.--.___.--.`;;
;-( o )=3D( o )-;
( `--' | `--' )
\| . . |/
........... . .:::::. . .______
/ . '---` . '\
.' `. .' \
| ____,.- . | `.....' | _______ |
| ,-' \ /|\'' \.-- |
| / \.'\ /,'. \. - |
| /| ` `\ / \ |
| ,/ _ '/ '\ |
,-' ,-. |o '
/ '| | | | \
/ ,/| |o | \ `
| .' | |.' |. \ \
________/ .'____|________________________||__`. `__________
( \ ) / )
'-. '-. ( .-` .-`
'-. .-'--.__. .-.__.--`-. .-`
'-..' \--' : ~`:=3D,`- `..-`
\ .. \\ |`-'|`-, /
\\\\\\\) | |`-'/.'/
\)\)\\ `-' `-'
`
 
P

Pawel Dziepak

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

kid said:
I guess the only remaining question is, why are there these two different
prototypes for the same function, even if they're functionally equivalent?

Despite the fact that implementation is the same, semantic is different.
CALLBACK informs that it is callback function (called from winapi
libraries). LRESULT stands for long type that stores function's return
value. WINAPI is used for functions that are part of WinAPI. LONG is
just kind of type (that probably has the same size on all platforms).

MSDN states that the correct prototype is:
LRESULT CALLBACK WindowProc(...);
What fits my explanation of CALLBACK, WINAPI, LONG and LRESULT semantics.

These definitions allows to change implementation or hardware platform
without breaking API compliance.

Pawel Dziepak

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkkMz5UACgkQPFW+cUiIHNrMVwCfSOOdFs3m1lMnNYDvtzfnMMWS
NgwAn1JPmkDB7ZkvrPFrAlvNSD6GH6Rk
=sDyQ
-----END PGP SIGNATURE-----
 
I

Ian Collins

kid said:
I guess the only remaining question is, why are there these two different
prototypes for the same function, even if they're functionally equivalent?
A windows group would be the place to ask.

Please don't post such a daft, ill-formed signature.
 
C

CBFalconer

Ian said:
A windows group would be the place to ask.

Please don't post such a daft, ill-formed signature.

He ignored the same request posted about 2 hours before his last
entry. If he continues again I guess the only solution is the
plonk file. Besides, his queries are all off-topic. He might read
the following references:

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://c-faq.com/> (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> (C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2> (pre-C99)
<http://www.dinkumware.com/c99.aspx> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>
 
G

George

Under 32 bit windows they are equivalent.
Under 64 bit windows they are not since LRESULT
is a 64 bit type and LONG is a 32 bit type...



WINAPI is _stdcall in 32 Bit windows
CALLBACK is also defined as _stdcall.

Under 64 bit windows _stdcall doesn't exist
so both definitions are equivalent too,
probably defined as nothing.

But it's not just windows stuff.

There is an aspect of callback functions that is

a) metasyntactic
b) relevant to standard C
--
George

Hundreds of thousands of American servicemen and women are deployed across
the world in the war on terror. By bringing hope to the oppressed, and
delivering justice to the violent, they are making America more secure.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
W

Wolfgang Draxinger

Default said:
Keith Thompson wrote:



Or at the very least a legal signature separator.

And if the OP wonders how that looks like: It's
"-- \n", i.e. 2 dashes, 1 space 1 newline.

Wolfgang Draxinger
 
K

kid joe

Got it, thanks. I guess just not worry about it in practise...

Joe

PS. For people who had problems with my sig, try using a fixed-width font
(i.e. Courier New) - I think you'll like it :)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Despite the fact that implementation is the same, semantic is different.
CALLBACK informs that it is callback function (called from winapi
libraries). LRESULT stands for long type that stores function's return
value. WINAPI is used for functions that are part of WinAPI. LONG is
just kind of type (that probably has the same size on all platforms).

MSDN states that the correct prototype is:
LRESULT CALLBACK WindowProc(...);
What fits my explanation of CALLBACK, WINAPI, LONG and LRESULT semantics.

These definitions allows to change implementation or hardware platform
without breaking API compliance.

Pawel Dziepak

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkkMz5UACgkQPFW+cUiIHNrMVwCfSOOdFs3m1lMnNYDvtzfnMMWS
NgwAn1JPmkDB7ZkvrPFrAlvNSD6GH6Rk
=sDyQ
-----END PGP SIGNATURE-----

--
.--------------------.
| |
| Good Evening.... | .--.--.
| | .; .;|;. ;.
`-------------. ,---' .;_;' `;_;.
\| ; ;' `; ;
\ ;;'.--.___.--.`;;
;-( o )=3D( o )-;
( `--' | `--' )
\| . . |/
........... . .:::::. . .______
/ . '---` . '\
.' `. .' \
| ____,.- . | `.....' | _______ |
| ,-' \ /|\'' \.-- |
| / \.'\ /,'. \. - |
| /| ` `\ / \ |
| ,/ _ '/ '\ |
,-' ,-. |o '
/ '| | | | \
/ ,/| |o | \ `
| .' | |.' |. \ \
________/ .'____|________________________||__`. `__________
( \ ) / )
'-. '-. ( .-` .-`
'-. .-'--.__. .-.__.--`-. .-`
'-..' \--' : ~`:=3D,`- `..-`
\ .. \\ |`-'|`-, /
\\\\\\\) | |`-'/.'/
\)\)\\ `-' `-'
`
 
J

James Kuyper

kid said:
Got it, thanks. I guess just not worry about it in practise...

Joe

PS. For people who had problems with my sig, try using a fixed-width font
(i.e. Courier New) - I think you'll like it :)

Using Courier New didn't make your signature 90% shorter, which is the
main thing that needs to be fixed.
 
K

Keith Thompson

kid joe said:
Got it, thanks. I guess just not worry about it in practise...

Joe

PS. For people who had problems with my sig, try using a fixed-width font
(i.e. Courier New) - I think you'll like it :)
[...]

I use a fixed-width font. The ASCII art you use as a signature is
reasonably impressive as ASCII art, but it's *way* too long as a
signature. The usual guideline (and I think this may be mentioned in
one of the RFCs) is that a signature should be no more than 4 lines,
not including the "-- " delimiter.
 
N

Nick Keighley

George said:
But it's not just windows stuff.

There is an aspect of callback functions that is

a) metasyntactic
b) relevant to standard C

he wasn't asking about callbacks though. He was asking specific
windows related questions that could only be answered by knowing about
various MS typedefs.

and what do you mean by "metasyntactic"?
Is that like Post Modernism?
 
C

CBFalconer

kid said:
Got it, thanks. I guess just not worry about it in practise...

PS. For people who had problems with my sig, try using a
fixed-width font (i.e. Courier New) - I think you'll like it :)

Since you ignore requests about your sig, and also top-post, you
have won an entry in the PLONK file. Goodbye.
 
K

Keith Thompson

CBFalconer said:
Since you ignore requests about your sig, and also top-post, you
have won an entry in the PLONK file. Goodbye.

He apparently misunderstood the original requests about his sig,
assuming incorrectly that people were complaining because it doesn't
display properly with a variable-width font. As for top-posting,
that's an easy mistake for a newbie to make, and easy to correct.

Suggested reading for kid joe:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

If he persists in using his inappropriately large sig, then plonking
might be appropriate, but for now I'm going to assume he's educable.
 
G

George

he wasn't asking about callbacks though. He was asking specific
windows related questions that could only be answered by knowing about
various MS typedefs.

That's the only syntax I know for it.
and what do you mean by "metasyntactic"?
Is that like Post Modernism?

Aspects of syntax that rise above indidual ones and characterize many.
They're the foo and bar and quuf.
--
George

Faith crosses every border and touches every heart in every nation.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
N

Nick Keighley

I don't see how you can answer this without knowing how MS
define LONG and LRESULT



it *is* just windows stuff


I still think this
That's the only syntax I know for it.

but he *** didn't ask a question about callbacks ****

long pippo (long (*Callback)(void*), void*);

that looks a pretty non-Windows way of specifying
a function that takes a callback


Aspects of syntax that rise above indidual ones and characterize many.
They're the foo and bar and quuf.

I know what metasyntactic means (eg. see the Jargon file). I don't
understand what foo, bar or pippo (an italian MSV) have to do with
callbacks.


--
Nick Keighley

atheist someone who doesn't believe in god
agnostic someone who isn't sure if he's an atheist
meta-agnostic someone who isn't sure if he's an agnostic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top