News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

what's the use of return 0 ?

Started by supercoollee, May 10, 2010, 07:46:00 AM

Previous topic - Next topic

hutch--

You acxtually need to understand what a return value is from a function and why it is that way. A function that returns OFFSET 0 in a file is not returning an error but a file pointer OFFSET. Its mainly boolean returns that are used for errors but that can be risky as well, the best way is to test for the error return value and find out WHY it failed.

I tend to use 0 for failure or error in a function unless zero is a valid return value for the function. There is no blanket usage that is always right and the need to actually use the function reference material will always be with us.


invoke Function,args etc ....
test eax, eax
jz failure
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

joemc

I believe the reason 0 is for success is so you can specify which error happened if it is non-zero.  But when you first start programing Win32 returning 0 for WM_NCCREATE may cause you to debug your application for a few hours.... It requires 1 for success... MSDN will be your friend before you learn all of them. 

The reason hutch said above is also what i have noticed too... If it is suppose to return a handle or pointer, it will generally be NULL for failure. and you will need to call GetLastError