PInvoke Custom Marshaling a Value type (Boxing)

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
 
M

Michael C

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top