Skip to content

Latest commit

 

History

History
38 lines (20 loc) · 2.61 KB

ii.22.22-implmap-0x1c.md

File metadata and controls

38 lines (20 loc) · 2.61 KB

II.22.22 ImplMap: 0x1C

The ImplMap table holds information about unmanaged methods that can be reached from managed code, using PInvoke dispatch. Each row of the ImplMap table associates a row in the MethodDef table (MemberForwarded) with the name of a routine (ImportName) in some unmanaged DLL (ImportScope).

[Note: A typical example would be: associate the managed Method stored in row N of the Method table (so MemberForwarded would have the value N) with the routine called "GetEnvironmentVariable" (the string indexed by ImportName) in the DLL called "kernel32" (the string in the ModuleRef table indexed by ImportScope). The CLI intercepts calls to managed Method number N, and instead forwards them as calls to the unmanaged routine called "GetEnvironmentVariable" in "kernel32.dll" (including marshalling any arguments, as required)

The CLI does not support this mechanism to access fields that are exported from a DLL, only methods. end note]

The ImplMap table has the following columns:

  • MappingFlags (a 2-byte bitmask of type PInvokeAttributes, §23.1.8)

  • MemberForwarded (an index into the Field or MethodDef table; more precisely, a MemberForwardedII.24.2.6) coded index). However, it only ever indexes the MethodDef table, since Field export is not supported.

  • ImportName (an index into the String heap)

  • ImportScope (an index into the ModuleRef table)

A row is entered in the ImplMap table for each parent Method (§II.15.5) that is defined with a .pinvokeimpl interoperation attribute specifying the MappingFlags, ImportName, and ImportScope.

This contains informative text only.

  1. ImplMap can contain zero or more rows

  2. MappingFlags shall have only those values set that are specified [ERROR]

  3. MemberForwarded shall index a valid row in the MethodDef table [ERROR]

  4. The MappingFlags.CharSetMaskII.23.1.7) in the row of the MethodDef table indexed by MemberForwarded shall have at most one of the following bits set: CharSetAnsi, CharSetUnicode, or CharSetAuto (if none is set, the default is CharSetNotSpec) [ERROR]

  5. ImportName shall index a non-empty string in the String heap [ERROR]

  6. ImportScope shall index a valid row in the ModuleRef table [ERROR]

  7. The row indexed in the MethodDef table by MemberForwarded shall have its Flags.PinvokeImpl = 1, and Flags.Static = 1 [ERROR]

End informative text.