Newbie Newbie - 8 months ago 64
C# Question

What is the C# equivalent of C++ DWORD?

After searching, I heard that UInt32 was the C# equivalent of C++ DWORD.
I tested results by performing the arithmetic

*(DWORD*)(1 + 0x2C) //C++
(UInt32)(1 + 0x2C) //C#

They produce completely different results. Can someone please tell me the correct match for DWORD in C#?


Your example is using the DWORD as a pointer, which is most likely an invalid pointer. I'm assuming you meant DWORD by itself.

DWORD is defined as unsigned long, which ends up being a 32-bit unsigned integer.

ulong (System.UInt64) is a 64-bit unsigned integer. So, it is larger than DWORD.

So these types are not the same. A closer match is UInt32.

#import <stdio.h>

// I'm on macOS right now, so I'm defining DWORD
// the way that Win32 defines it.
typedef unsigned long DWORD;

int main() {
    DWORD d = (DWORD)(1 + 0x2C);
    int i = (int)d;
    printf("value: %d\n", i);
    return 0;

Output: 45

public class Program
    public static void Main()
        ulong d = (ulong)(1 + 0x2C);
        System.Console.WriteLine("Value: {0}", d);

Output: 45