[Mono-list] Can I call CoTaskMemAlloc on Linux?
Robert Jordan
robertj at gmx.net
Thu Mar 15 14:13:53 EDT 2007
Vincent Finn wrote:
> Hi,
>
> I am sure this is a stupid question but I wanted to check before going
> down the wrong route.
>
> On windows I am passing IntPtrs from C# to C++ and them using
> SysAllocString on "UnmanagedType.LPWStr" and CoTaskMemAlloc on structs
> when I want to return memory.
>
> In Visual Studio I need to include "oleauto.h" to get those functions,
> and I then need to include "windows.h" to get various #defines used in
> "oleauto.h".
>
> "windows.h" won't be on a Linux machine so can someone confirm for me
> that CoTaskMemAlloc is portable and not MS?
>
> If it isn't what is the alternative?
Instead of p/invoking you should use the following methods
that do the right thing regardless of the platform:
System.Runtime.InteropServices.Marshal.AllocCoTaskMem
and
System.Runtime.InteropServices.Marshal.FreeCoTaskMem
Robert
More information about the Mono-list
mailing list