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 la开发者_开发问答unching 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,
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
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);
A DWORD in C# would be a uint (UInt32).
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.
精彩评论