PInvoke Custom Marshaling a Value type (Boxing)

  • Thread starter Thread starter Bill Medland
  • Start date Start date
B

Bill Medland

I am trying to do some P/Invoke custom marshaling and am looking for a
little help on custom marshaling a value type.

I am working based on Kate Gregory's "Arranging Custom Marshaling With
P/Invoke", which is unfortunately in C++ with managed extensions; I am
working in C#.

As with Kate's example I want to marshal from a System.DateTime to a
proprietary format. However I cannot figure out how to tell the system
to box the DateTime. Can anyone tell me the C# equivalent of __box?

I guess what I want is the C# equivalent of this:

[DllImport("legacy")] bool MyFunc ([In,
MarshalAs(UnmanagedType::CustomMarshaler,
MarshalTypeRef=__typeof(MYDATETYPE_CustomMarshaler))]
__box DateTime* time);

TIA

Bill Medland
 
Bill Medland said:
I am trying to do some P/Invoke custom marshaling and am looking for a
little help on custom marshaling a value type.

I am working based on Kate Gregory's "Arranging Custom Marshaling With
P/Invoke", which is unfortunately in C++ with managed extensions; I am
working in C#.

As with Kate's example I want to marshal from a System.DateTime to a
proprietary format. However I cannot figure out how to tell the system
to box the DateTime. Can anyone tell me the C# equivalent of __box?

I guess what I want is the C# equivalent of this:

[DllImport("legacy")] bool MyFunc ([In,
MarshalAs(UnmanagedType::CustomMarshaler,
MarshalTypeRef=__typeof(MYDATETYPE_CustomMarshaler))]
__box DateTime* time);

Can't you do this another way, such as creating a structure to pass in or
passing in an IntPtr instead?

Michael
 
Back
Top