G
Guest
I have this situtaition.
I want to extract the top most byte from a DWORD (uint in C#).
In C++ I would use some macros like HIBYTE( HIWORD(version)))
Or use another way like byte *ptrByte = (byte*)version; iReturn=ptrByte[3];
So I try to do this in C# using the unsafe, but I get this exception:
e.Message "Object reference not set to an instance of an object." string
Any tips how to do this in a C# style? I also fought with the *fixed*
function but that one has problems between uint* and byte*
The code below compiles.
------------------------------
public int GetVersion() {
int iReturn=-1;
try {
uint version=0x12345678;
unsafe {
byte *ptrByte = (byte*)version;
iReturn=ptrByte[3];
}
} catch (Exception e) {
MessageBox.Show(e.Message, "Critical Error!");
}
return iReturn;
}
}
I want to extract the top most byte from a DWORD (uint in C#).
In C++ I would use some macros like HIBYTE( HIWORD(version)))
Or use another way like byte *ptrByte = (byte*)version; iReturn=ptrByte[3];
So I try to do this in C# using the unsafe, but I get this exception:
e.Message "Object reference not set to an instance of an object." string
Any tips how to do this in a C# style? I also fought with the *fixed*
function but that one has problems between uint* and byte*
The code below compiles.
------------------------------
public int GetVersion() {
int iReturn=-1;
try {
uint version=0x12345678;
unsafe {
byte *ptrByte = (byte*)version;
iReturn=ptrByte[3];
}
} catch (Exception e) {
MessageBox.Show(e.Message, "Critical Error!");
}
return iReturn;
}
}