Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c#

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#?

like image 858
Newbie Avatar asked Oct 10 '16 04:10

Newbie


People also ask

What is C language in simple words?

What Does C Programming Language (C) Mean? C is a high-level and general-purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System in the early 1970s.

What is C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C for computer?

C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on. C programming is an excellent language to learn to program for beginners.


1 Answers

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.

uint (System.UInt32) should be a match.

#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()
    {
        uint d = (uint)(1 + 0x2C);
        System.Console.WriteLine("Value: {0}", d);
    }
}

Output: 45

like image 186
Stephen Jennings Avatar answered Sep 25 '22 21:09

Stephen Jennings