devxlogo

DWORD Equivalent

DWORD Equivalent

Question:
I’m trying to translate from VC++ to Java. Can you declare a variableDWORD in Java? If not, what is the Java equivalent?

Also, what is theequivalent for HINSTANCE?

Answer:
Java differs from C and C++ in that all of its fundamental data types havespecified sizes that are guaranteed to be the same across allplatforms. In C, the size of an integer can vary from compiler tocompiler and platform to platform. When Microsoft moved from 16-bitDOS and Windows 3.1 to 32-bit Windows 95 and NT, they tried toabstract the fundamental types in order to facilitate the maintenanceof a single code-base for different memory architectures. Therefore,a DWORD may be represented by a different native C type on Windows 95for Intel processors and NT 4.0 for Alpha processors.

There is no need to abstract the fundamental data types because Javadefines a fixed size for all of its data types. To answer your firstquestion: no, you cannot declare a variable as a Visual C++ DWORD inJava. The Microsoft types are also ill-designed because a WORD isactually a 16-bit unsigned integer value in 32-bit Windows 95, whereyou would expect a WORD to be a 32-bit unsigned integer value. ADWORD is a 32-bit unsigned integer value. Java does not supportunsigned integer types other than char, which you shouldn’t think ofas an integer type, so there is no Java equivalent to a DWORD. Youcould use an int, which is 32 bits, if you are only concerned aboutbit values?or a long, which is 64 bits, if you want to easilymanipulate the range of 32 bit unsigned values.

HINSTANCE is usuallya void pointer, for which the closest Java analog is an Objectreference.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist