473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

newby. Why are these values defined as they are

I'm reading through some source code written by microsoft to show examples
of porting serial comms to .net.

Anyone who has written comms will know the following constants well.

Can anyone explain why the programmer chose the various variable types and
why some have been initialized so differently in the declaration.

Thanks

internal const int GENERIC_READ = unchecked((int) 0x80000000);

internal const int GENERIC_WRITE = 0x40000000;
internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);

internal static readonly IntPtr NULL = IntPtr.Zero;
Nov 16 '05 #1
1 1014
I'm not for certain on all of these, but here are my guesses :)

internal const int GENERIC_READ = unchecked((int) 0x80000000);
internal const int GENERIC_WRITE = 0x40000000;
Both are declared as constant int so that they cannot be modified after
declaration. internal means that the members are only accessible to types
within the same assembly.

The unchecked keyword turns of runtime bounds-checking I believe. You may
want to investigate this further.

Also, the 0x notation indicates a hex constant.
internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
readonly means the variable can only be assigned to during the initial
declaration (or for an instance field, in the instance constructor of the
class that declares the variable).

This variable is probably used to check against handles returned from win32
api functions to make sure they are valid.

ie:
myHandle = someAPIFunction();
if (myHandle == INVALID_HANDLE_VALUE)
// error
internal static readonly IntPtr NULL = IntPtr.Zero;


This delcares an empty (null) pointer. Similar to the INVALID_HANDLE_VALUE
variable, it is probably used to make sure that pointers are not null before
using them.

Hope this helps.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Jack Schitt | last post by:
I thought I was starting to get a handle on Access, until I tried doing something useful...now I'm stuck. I have a DB with two tables - to keep it simple I'll say that one is an Employee File...
7
by: William L. Bahn | last post by:
I'm working on some lessons and want to be sure I get some stuff correct. If any of this is covered in the FAQ, please feel free to point me to the section - I couldn't find it. ...
10
by: Fred Nelson | last post by:
Hi: I have programmed in VB.NET for about a year and I'm in the process of learing C#. I'm really stuck on this question - and I know it's a "newby" question: In VB.NET I have several...
2
by: johnnyG | last post by:
Greetings, I'm studying for the 70-330 Exam using the MS Press book by Tony Northrup and there are 2 side-by-side examples of using the SHA1CryptoServiceProvider to create a hash value from a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.