Does anyone know where a good list of persistent windows lives

I'm trying to set an invalid value -1 .. But I don't like magic numbers. Does anyone know where to find a set of common constants. I am working in VS6 (ish).

I am trying to read a file from the net and I need a bad value for the total file size, so I know if I have reliable information on this. 0 is a valid size, so I cannot use that.

Harper Shelby HIT THE NAIL ON THE HEAD .. Just a little thumb. He mentioned win32 constants .. this is exactly what I was thinking .. Now to find the link :)

-2


source to share


8 answers


#define BAD_VALUE -1

      



EDIT: The original question has no context whatsoever. The revised question indicates that you want an invalid file size and is thus looking for win32 constants. Have a look at windows.h I think the constant you are looking for might be in windows.h or one of its sub-inclusions. grep your windows include a directory; -)

+2


source


If -1 is not a valid return value on your system, you must define it internally:

const int INVALID_FOO = -1

      

unless C compatibility is required, in which case



#define INVALID_FOO -1

      

would be preferable. If it is a standard MFC or Windows resource, use INVALID_HANDLE or one of the other Win32-defined constants.

+2


source


You want to use your own magic number -1 disguised as a Windows persistent. This is very misleading.

Suppose I know INVALID_HANDLE is 0. Do I need to initialize my pointers with INVALID_HANDLE?

char *myMessage = INVALID_HANDLE;

      

How will that amaze you?

+1


source


In VS, Create a new Windows Console Application Project. Go to project settings and enable search support. Create a C ++ file and add it to your project. A type:

#include <windows.h>
void main(void) {}

      

to the file. Compile it. Now enter INVALID_FILE_SIZE. Right click on it and select the INVALID_FILE_SIZE definition. VS will open one of the many window title files full of specific values. Enjoy.

+1


source


First, you must use unsigned int for the file size, since the file size will never be negative. Now the invalid file size is usually the maximum, so in the case of using a 32-bit unsigned int it would be 0xFFFFFFFF

i.e.

const unsigned int INVALID_FILESIZE = 0xFFFFFFFF;

      

Also, if it is specified in windows, Windows.h defines an invalid file size everything is done (INVALID_FILE_SIZE)

+1


source


If you want to use the constants used by WinApi, check the WinError.h, WinUser.h, and WinNT.h files.

+1


source


It is generally accepted that 0s and 1s (positive and negative) are okay to use directly.

In fact, this will probably make your code even more confusing to use a variable.

Update: OK, you updated your question after I wrote my answer. If you use "-1" arithmetically, then just "-1" is fine. If you are returning an error code (and the code is just -1), you must use a constant.

 const int INVALID_VALUE = -1;

      

-1


source


If bytes_read < 0
    // error
EndIf

      

-1


source







All Articles