0

I am usisng GetExitCodeProcess(processInfo.hProcess, out returnCode) as a p/invoke in C# to get the turn code of a process I started using CreateProcess - everything works fine ...

This is the code:

UInt32 returnCode = 0xFFFFFFFF;     // default
GetExitCodeProcess(processInfo.hProcess, out returnCode);

The issue is the return code itself ... the application I am launching returns codes in DWORD, for example it returns 0XB2100000 but returnCode has 2987393024 (which is the correct INT conversion).

Now, I would like to show (log to my trace file) the value in DWORD (that is what we are used to) - anyway I can do this?

Thanks,

Shaitan00
  • 283
  • 1
  • 6
  • 19

4 Answers4

1

Log the returnCode like this:

String.Format("0x{0:X8}", returnCode)

or

returnCode.ToString("X8").Insert(0, "0x")

This issue is also covered here:

c# convert int to hex and back again

Community
  • 1
  • 1
João Angelo
  • 51,934
  • 12
  • 129
  • 140
1

It seems that it just has to be converted to a hexadecimal form, like this:

    returnCode.ToString("X8");

or like this:

Console.WriteLine("The error code was {0:X8}.", returnCode);
treaschf
  • 5,263
  • 1
  • 23
  • 24
0

A DWORD in C# would be a uint (UInt32).

Chad Moran
  • 12,704
  • 2
  • 45
  • 71
0

A DWORD and an INT are the same thing*. What you are wondering about has to do with whether a number is represented in base-10 or base-16. However, they are still the same numbers. 32 === 0x20, they are identical, not even automatically converted to eachother. Usually when you care about the base, what you are really looking for is bitwise operations (look up the operators &, | and ~).

*yes, I know DWORDs are unsigned and INTs are signed.

erikkallen
  • 31,744
  • 12
  • 81
  • 116