[DllImport("PInvokeNative", CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr GetFunctionPointer();
+ [DllImport("PInvokeNative", CallingConvention = CallingConvention.StdCall)]
+ internal static extern IntPtr GetNativeFuncFunctionPointer();
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal unsafe struct InlineString
TestForwardDelegateWithUnmanagedCallersOnly();
TestDecimal();
TestDifferentModopts();
+ TestFunctionPointers();
return 100;
}
Marshal.GetDelegateForFunctionPointer<SetLastErrorFuncDelegate>(procAddress);
funcDelegate(0x204);
ThrowIfNotEquals(0x204, Marshal.GetLastWin32Error(), "Not match");
+ }
+
+ private static unsafe void TestFunctionPointers()
+ {
+ IntPtr procAddress = GetNativeFuncFunctionPointer();
+ delegate* unmanaged[Cdecl] <int, int> unmanagedFuncDelegate =
+ (delegate* unmanaged[Cdecl] <int, int>)procAddress;
+ var result = unmanagedFuncDelegate(100);
+ ThrowIfNotEquals(1422, result, "Function pointer did not set expected error code");
}
static int Sum(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
Action a = Marshal.GetDelegateForFunctionPointer<Action>((IntPtr)(void*)(delegate* unmanaged<void>)&UnmanagedCallback);
a();
}
-
+
public static unsafe void TestDifferentModopts()
{
byte storage;