1

I try to marshal NdisGetCurrentSystemTime result to a C# program via ioctl.

LARGE_INTEGER data;
NdisGetCurrentSystemTime (&data );
marshal_data->time = (UINT64)(data.QuadPart / 10^6);
    DBGPRINT(("Time: %64u", marshal_data->time));

At C# receiver side, the time field is defined as uint64; there's also a couple of other uint64 fields in the marshalled structure. However, when doing

    String.Format(("Time was {0}", recv_data->time)) 

I get unexpectedly large number that differs from the one in DBGPRINT.

C#:

    [StructLayout(LayoutKind.Sequential)]
    ...
    public UInt64 time

C:

    struct _marshalme {
    ... 
    UINT64 time
    ...
    }

Is there anything going weird with a byte order?

kagali-san
  • 2,964
  • 7
  • 48
  • 87
  • Your DBGPRINT does not print the time, it misses a parameter: `DBGPRINT(("Time: %64u"));` – wimh Dec 11 '11 at 09:12
  • 4
    10^6 doesn't make sense either. The simple explanation is that the C# structure declaration is just wrong so that the field gets misaligned. You avoided a good answer by not posting the complete declarations. – Hans Passant Dec 11 '11 at 12:33
  • @Wimmel, in actual version, there is a parameter. I've been trying to avoid posting lots of code to get a minimal example though. fixing. – kagali-san Dec 11 '11 at 15:27
  • 2
    It's very difficult to help when we have to guess at what your code looks like. – David Heffernan Dec 11 '11 at 19:36

2 Answers2

0

LARGE_INTEGER represents a 64-bit signed integer. I expect your problems come from using UInt64 instead of Int64.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
  • but the only difference between signed and unsigned is the most significant bit. That should be unset, which means the value should be the same whether taken as a signed or unsigned value. – phoog Dec 11 '11 at 15:04
0

The problem was mainly in improper struct alignment thus different size; but for some reason, it seems to keep damaging data at transfer (e.g. last DBGPRINT prints saved value correctly) for int32, int64 cases even when size is same; I've been forced to use

  long startTime;
  long padding;

to receive proper value as C#'s long, other ways of marshalling that value failed. Will post more completed sample later, unless that - the question is closed.

kagali-san
  • 2,964
  • 7
  • 48
  • 87
  • The fact that the issue was struct alignment shows how lacking in detail the question was. You really didn't give us anywhere near enough information to tackle the problem. – David Heffernan Dec 12 '11 at 21:51