473,490 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PInvoke Custom Marshaling a Value type (Boxing)

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

Mar 16 '06 #1
1 2662
"Bill Medland" <bi*********@mercuryspeed.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
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
Mar 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
338
by: vijaya | last post by:
I've a problem with PInvoke.I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.Please apologise for this lenghty message and render ur kind help. The original dll...
1
348
by: Muthiah Samy | last post by:
Hi All, I am trying to call COM Component in .NET using PInvoke. I have rewritten custom IDL file in a managed language(C#). When I try to invoke one of the COM method from .NET, I am getting...
24
2570
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
0
1721
by: jim4u | last post by:
I am porting a vb library to vb.net. The vb library has an external call to an unmanaged dll. Existing code: //External function declaration Private Declare Function Uncompress& Lib...
4
2361
by: Mathieu Cartoixa | last post by:
Hi, I have been annoyed in one of my recent projects with a problem related to the explicit implementation of an interface on a value type. I will take an example to show the problem. Say we...
4
2271
by: Jon Slaughter | last post by:
I'm reading a book on C# and it says there are 4 ways of passing types: 1. Pass value type by value 2. Pass value type by reference 3. Pass reference by value 4. Pass reference by reference. ...
0
1857
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to...
2
3067
by: Ashutosh | last post by:
pInvoke - arguments marshaling Hi, I am using pInvoke and the member function has signature like this in C++ int F1(ULONG handle, LPCTSTR s1, LPCTSTR s2, LPCTSTR s3, LPCTSTR s4) so, I am...
1
1436
by: jehugaleahsa | last post by:
Hello: I am experiencing performance related issues when my custom data structures work with value types. I use generics to prevent boxing wherever I can. For instance, I use IEqualityComparer,...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.