PInvoke Win32 function for Marshal.PtrToStructure in Silverlight 5

I used

public static Object PtrToStructure(
IntPtr ptr,
Type structureType
)

as

private static object ReadStruct(byte[] buffer, Type t)
{
    GCHandle handle =
        GCHandle.Alloc(buffer,
        GCHandleType.Pinned);
    Object temp =
        Marshal.PtrToStructure(
        handle.AddrOfPinnedObject(),
        t);
    handle.Free();
    return temp;
}

for marshaling data in .net 4.0. Silverlight does not support this method. According to the next article, the .net method is just a wrapper for the native win32 function. An example was given for Marshal.AllocHGlobal (Win32 LocalAlloc function from Kernel32.dll)

http://blogs.msdn.com/b/silverlight_sdk/archive/2011/09/27/pinvoke-in-silverlight5-and-net-framework.aspx

These are new waters as SL5 simply included pInvoke for trusted applications (in the browser). What is the win32 function that PtrToStructure wraps, and is there anything that prevents it from being used in SL5?

+1
source share
1 answer

, , PtrToStructure(IntPtr, Type) mscorlib.dll Silverlight 5:

[SecurityCritical]
[ComVisible(true)]
[FriendAccessAllowed]
internal static object PtrToStructure(IntPtr ptr, Type structureType)

internal, , , . PtrToStructure, , :

[MethodImpl(MethodImplOptions.InternalCall)]
private static void PtrToStructureHelper(IntPtr ptr, object structure, bool allowValueClasses);

.

win32, PtrToStructureHelper. , PtrToStructure [SecurityCritical], , Silverlight P/Invoke win32, , .

+1

All Articles