Title: some questions about win32
NOFX - February 27, 2005 09:10 PM (GMT)
I have some questions about some codes in win32 programming. I learned win32 programming from alot of different tutz so sorry for my lack of knowledge here.
When i view codes of some apps i often see functions declared like this.
| CODE |
DWORD WINAPI SomethingProc(LPVOID lParam) { //codes return 0; }
BOOL CALLBACK SomeFunctionProc(HWND hwnd, LPARAM lParam) { //codes return true; //why true? }
|
What i want to know is when do you use function like that, why are they good for etc. Can someone please enlighten me.
Joel - February 28, 2005 03:14 AM (GMT)
In the function SomethingProc uses the return 0 (zero) because some Win32 functions uses that return indicating that the function exists succesfully. For example:
| CODE |
int TehProc(int iParam) { if (iParam <= 256) return 0; // everything is Ok... return 1; // oops! we have a problem }
|
in SomeFunctionProc is the same TRUE nor FALSE will tell you the returning state of the function:
| CODE |
BOOL TehFunc(int iParam) { if (iParam <= 256) return TRUE; // yay! return FALSE; // ooops! bad! Let's return false so the user will handle it }
|
NOFX - February 28, 2005 12:18 PM (GMT)
Thanks, thats clears it up for me about the "return true" and "return 1"
Can you also tell me what the differents is if i use a function like
BOOL CALLBACK MyFunc1()
and
DWORD WINAPI MyFunc2()
Is this C Style ? And is could i just replace DWORD WINAPI MyFunc1() with:
int MyFunc1()
Thats the only part i dont understand.
Viper - February 28, 2005 02:17 PM (GMT)
DWORD = Double word.
Double word = 2 words.
1 word = 4 bytes.
1 byte = 8 bit.
BOOL = Boolean.
I think boolean is 8 bit but don't think about that.
The difference between them is the return.
I don't think you can replace DWORD WINAPI with int because of the WINAPI.
Joel - February 28, 2005 02:24 PM (GMT)
1.- BOOL CALLBACK MyFunc1() is returning TRUE (1) or FALSE (0). DWORD WINAPI MyFunc2() is returning a DWORD (doble word) cast, which can be a integer too. The thing is that, since BOOL is watting for a TRUE or FALSE value and DWORD, not only can be 1 or 0, can be another integer number, also an hexadecimal one(see cast and types)... so...watch those returning types and values :)
2.- Yes, is C style :)
3.- Yes, you can replace DWORD with int.... is a simple cast convertion ;)
NOFX - February 28, 2005 03:17 PM (GMT)
Thanks alot for the explanation guys :)