System.Reflection.Emit.ModuleBuilder.DefinePInvokeMethod Method

Defines a PInvoke method with the specified name, the name of the DLL in which the method is defined, the attributes of the method, the calling convention of the method, the return type of the method, the types of the parameters of the method, and the PInvoke flags.

Syntax

public MethodBuilder DefinePInvokeMethod (string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet)

Parameters

name
The name of the PInvoke method. name cannot contain embedded nulls.
dllName
The name of the DLL in which the PInvoke method is defined.
entryName
The name of the entry point in the DLL.
attributes
The attributes of the method.
callingConvention
The method's calling convention.
returnType
The method's return type.
parameterTypes
The types of the method's parameters.
nativeCallConv
The native calling convention.
nativeCharSet
The method's native character set.

Returns

The defined PInvoke method.

Remarks

Some DLL import attributes (see the description of System.Runtime.InteropServices.DllImportAttribute) cannot be specified as arguments to this method. Such attributes should be set by emitting a custom attribute for the method. For example, the DLL import attribute PreserveSig is set by emitting a custom attribute.

Note:

Starting with the net_v20sp1_long, this member no longer requires System.Security.Permissions.ReflectionPermission with the System.Security.Permissions.ReflectionPermissionFlag.ReflectionEmit flag. (See Security Issues in Reflection Emit.) To use this functionality, your application should target the net_v35_long or later.

Requirements

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0