Theos PowerBasic Museum 2017

General Category => General Discussion => Topic started by: George Towler on June 28, 2010, 11:50:27 PM

Title: Why is ULONG translated as DWORD
Post by: George Towler on June 28, 2010, 11:50:27 PM
Microsoft define ULONG
Quote
ULong Data Type (Visual Basic)

Holds unsigned 64-bit (8-byte) integers ranging in value from 0 through 18,446,744,073,709,551,615 (more than 1.84 times 10 ^ 19).

and PowerBasic define DWORD

Quote
Double-words are 32-bit (four byte) unsigned  with a range of 0 to 4,294,967,295  ( 0 to 2^32-1). 

You see this translation in loads of places and it seems to work. I especially don't understand how it can work as an element in a UDT.
Title: Re: Why is ULONG translated as DWORD
Post by: José Roca on June 29, 2010, 12:02:57 AM
 
When using a 32-bit OS or compiler, an ULONG is a 32 bit unsigned integer, i.e. a DWORD. It will be a QUAD when using a 64 bit compiler.
Title: Re: Why is ULONG translated as DWORD
Post by: George Towler on June 29, 2010, 01:37:01 AM
That makes sense. Thanks  (seems odd to me that microsoft didn't make that distinction in their definition)
Title: Re: Why is ULONG translated as DWORD
Post by: Frederick J. Harris on June 29, 2010, 04:13:08 PM
About two weeks ago I got to studying up on that a bit (what the data types will look like in 64 bit Windows), and I had found a good link about it I can't locate now, but the gist of it I thought was that ULONGs and DWORDs in C speak were still going to be 32 bits so as not to take up room unnecessarily or break existing code.  What the article stated was that the big change was going to be in pointers so that they could access that horrendously large 64 bit address space.  So is that thing with a ULONG in Visual Basic being 64 bits just something unique to VB I'm wondering?

Title: Re: Why is ULONG translated as DWORD
Post by: José Roca on June 29, 2010, 04:32:38 PM
 
Quote
So is that thing with a ULONG in Visual Basic being 64 bits just something unique to VB I'm wondering?

It has to do with .NET. They decided to call integers as Short, longs as Integer and signed quads as Long. Therefore, in .NET an ULong is an unsigned quad. In C++, an ULONG is a DWORD.
Title: Re: Why is ULONG translated as DWORD
Post by: Mike Stefanik on June 29, 2010, 05:04:36 PM
Quote from: José Roca on June 29, 2010, 12:02:57 AM
When using a 32-bit OS or compiler, an ULONG is a 32 bit unsigned integer, i.e. a DWORD. It will be a QUAD when using a 64 bit compiler.

Actually that's not quite right in the .NET world. The ULong data type in VB.NET is an alias for the System.UInt64 type, so it's 64-bit regardless of whether the target platform is x86 or x64. In .NET, the polymorphic data types that change width based on the target platform is the System.IntPtr and System.UIntPtr types, which are 32-bit on x86 and 64-bit on x64; they're analagous to INT_PTR and UINT_PTR used with the Windows SDK.

Bottom line, if you see ULong used in a .NET program, it's always 64-bits. If you see ULONG used in C/C++ prototypes, such as the Windows SDK, it's always 32-bits.