Copying data onto unmanaged memory in C#

  • Thread starter Thread starter Luk Vloemans
  • Start date Start date
L

Luk Vloemans

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
 
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
 
Back
Top