iOS Guides | Samples

ObjCRuntime.MonoPInvokeCallbackAttribute Class

Attribute used to annotate functions that will be called back from the unmanaged world.

See Also: MonoPInvokeCallbackAttribute

Syntax

[System.AttributeUsage(System.AttributeTargets.Method)]
public sealed class MonoPInvokeCallbackAttribute : Attribute

Remarks

This attribute is valid on static functions and it is used by Mono's Ahead of Time Compiler to generate the code necessary to support native call calling back into managed code.

In regular ECMA CIL programs this happens automatically, and it is not necessary to flag anything specially, but with pure Ahead of Time compilation the compiler needs to know which methods will be called from the unmanaged code.

In the current version of MonoTouch, only static functions can be called back from unmanaged code.

You must specify the type of the delegate that this code will be called as. The following example shows the scenario in which this is used:

C# Example

using System;
	delegate void DrawPatternCallback (IntPtr voidptr, IntPtr cgcontextref);

	[StructLayout (LayoutKind.Sequential)]
	struct SetupStruct {
	 	int x, y;
		DrawPatternCallback draw;
	}

	[MonoPInvokeCallback (typeof (DrawPatternCallback))]
	static void DrawCallback (IntPtr voidptr, IntPtr cgcontextptr)
	{
		// This method is called from the C library
	}

Requirements

Namespace: ObjCRuntime
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0

The members of ObjCRuntime.MonoPInvokeCallbackAttribute are listed below.

See Also: Attribute

Public Constructors

Constructor for the MonoPInvokeCallbackAttribute.

Public Properties