-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Interoperability.MarshalBooleansInPInvokeDeclarationsRule(git)
Assembly: Gendarme.Rules.Interoperability
Version: git
This rule warns the developer if a MarshalAs attribute has not been specified for boolean parameters of a P/Invoke method. The size of boolean types varies across language (e.g. the C++ bool type is four bytes on some platforms and one byte on others). By default the CLR will marshal System.Booleanas a 32 bit value (UnmanagedType.Bool ) like the Win32 API BOOLuses. But, for clarity, you should always specify the correct value.
Bad example:
// bad assuming the last parameter is a single byte being mapped to a bool
[DllImport ("liberty")]
private static extern bool Bad (bool b1, ref bool b2);
Good example:
[DllImport ("liberty")]
[return: MarshalAs (UnmanagedType.Bool)]
private static extern bool Good ([MarshalAs (UnmanagedType.Bool)] bool b1, [MarshalAs (UnmanagedType.U1)] ref bool b2);
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!