ssg31415926
11/15/2007 11:18:00 AM
I think I've figured it out by going back to basics and going through
the byte array byte-by-byte. It seems that I should translate it like
this:
byte1 + byte2 * 256 + byte3 * 65536 + byte4 * 16777216
or
double offset = 0;
for (int j = 0; j < 4; j++)
{
offset = offset + Math.Pow(256, j) * offsetBytes[j];
}
return (uint)offset;
where offsetBytes is the byte array with the relevant values.
Still, I feel that there should be a built-in way of doing this as it
must be quite common. E.g. I need it to write an extension property
sheet in a MMC 3.0 extension to Active Directory Users and Computers.
One further question: should I be using the same method to translate
the uint in the DSOBJECTNAMES structure?
ssg31415926 wrote:
> I have a byte array and I'm trying to translate a DWORD in that array
> into an integer so that I can use it as an offset into a later part of
> the array. Once I get the offset, I've successfully worked out how to
> translate the offset part into a string but I can't work out how to
> translate the offset itself.
>
> I'm trying to interpret this structure:
>
> typedef struct {
> CLSID clsidNamespace;
> UINT cItems;
> DSOBJECT aObjects[1];
> } DSOBJECTNAMES,
> *LPDSOBJECTNAMES;
>
> which contains count cItems of this structure:
>
> typedef struct {
> DWORD dwFlags;
> DWORD dwProviderFlags;
> DWORD offsetName;
> DWORD offsetClass;
> } DSOBJECT,
> *LPDSOBJECT;