PC Review


Reply
Thread Tools Rate Thread

Copying data onto unmanaged memory in C#

 
 
Luk Vloemans
Guest
Posts: n/a
 
      2nd Sep 2003
Hi,

I'm trying to copy data onto unmanaged memory in C#.

I found the how you would normally do it in C++:

uint eventMask = 0;
IntPtr uMask = Marshal.AllocHGlobal(Marshal.SizeOf(eventMask));
Marshal.WriteInt32(uMask, 0); //0 is just a random value.

Does anybody know how to do this in C# ?
The problem is, C# (on Compact .Net Framework) doesn't support the
AllocHGlobal property of the class Marshal.

Anybody any idea ?

Thanks in advance!

-Luk Vloemans
IT student


 
Reply With Quote
 
 
 
 
Neil Cowburn [MVP]
Guest
Posts: n/a
 
      2nd Sep 2003
You will need to P/Invoke LocalAlloc (found in coredll.dll) instead of
calling Marshal.AllocHGlobal. Don't forget to call FreeLocal when you are
done to free up the unmanaged memory.

Interestingly, OpenNETCF.org have a custom Marshal class in the works which
supports AllocHGlobal/FreeHGlobal.

HTH
Neil

--
Neil Cowburn
Microsoft Windows Embedded MVP



"Luk Vloemans" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I'm trying to copy data onto unmanaged memory in C#.
>
> I found the how you would normally do it in C++:
>
> uint eventMask = 0;
> IntPtr uMask = Marshal.AllocHGlobal(Marshal.SizeOf(eventMask));
> Marshal.WriteInt32(uMask, 0); //0 is just a random value.
>
> Does anybody know how to do this in C# ?
> The problem is, C# (on Compact .Net Framework) doesn't support the
> AllocHGlobal property of the class Marshal.
>
> Anybody any idea ?
>
> Thanks in advance!
>
> -Luk Vloemans
> IT student
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to use unmanaged buffer as a Byte []? preferably w/o copying from native to managed memory lallous Microsoft VC .NET 1 27th Mar 2007 04:02 PM
Copying data from unmanaged buffer to local array David Smith Microsoft C# .NET 0 1st Dec 2004 02:33 PM
Re: Copying unmanaged memory pointer of structure to managed structure array Mattias Sjögren Microsoft VC .NET 0 28th Aug 2004 03:19 PM
Copying data onto unmanaged memory in C# Luk Vloemans Microsoft Dot NET Framework 1 3rd Sep 2003 10:34 AM
Copying data onto unmanaged memory in C# Luk Vloemans Microsoft C# .NET 0 2nd Sep 2003 12:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:52 AM.