13,007
回編集
編集の要約なし |
|||
142行目: | 142行目: | ||
<u>※注意</u><br> | <u>※注意</u><br> | ||
<u>上記の例では、UInt32型はCLSに準拠しないため、<code>CLSCompliant(false)</code>と指定する必要がある。</u><br> | <u>上記の例では、UInt32型はCLSに準拠しないため、<code>CLSCompliant(false)</code>と指定する必要がある。</u><br> | ||
<br><br> | |||
== SuppressUnmanagedCodeSecurity属性 == | |||
SuppressUnmanagedCodeSecurity属性は、アンマネージドコードの呼び出し時に実行されたスタックウォークを、実行時に省いて効率を大幅に向上させる。<br> | |||
<br> | |||
詳細は、以下のMSDNのWebサイトを参照すること。<br> | |||
[https://msdn.microsoft.com/ja-jp/library/system.security.suppressunmanagedcodesecurityattribute.aspx SuppressUnmanagedCodeSecurityAttribute クラス | MSDN]<br> | |||
<br><br> | |||
== MarshalAs属性 == | |||
MarshalAs属性は、マネージドコードとアンマネージドコードの間で、データをマーシャリングする方法を指定する。<br> | |||
<br> | |||
詳細は、以下のMSDNのWebサイトを参照すること。<br> | |||
[https://msdn.microsoft.com/ja-jp/library/system.runtime.interopservices.marshalasattribute.aspx MarshalAsAttribute クラス (System.Runtime.InteropServices) | MSDN]<br> | |||
<source lang="csharp"> | |||
// パラメータへの適用 | |||
public void M1([MarshalAs(UnmanagedType.LPWStr)]string msg) | |||
{ | |||
} | |||
// クラスのフィールドへの適用 | |||
class MsgText | |||
{ | |||
[MarshalAs(UnmanagedType.LPWStr)] | |||
public string msg = "Hello World"; | |||
} | |||
// 戻り値への適用 | |||
[return: MarshalAs(UnmanagedType.LPWStr)] | |||
public string GetMessage() | |||
{ | |||
return "Hello World"; | |||
} | |||
</source> | |||
<br><br> | |||
== In属性 / Out属性 == | |||
In属性 / Out属性は、データの渡し方を指示する。<br> | |||
<center> | |||
{| class="wikitable" | |||
|- | |||
! !! 説明 | |||
|- | |||
| In属性 || 呼び出し側にデータをマーシャリングして渡すことを示す。 | |||
|- | |||
| Out属性 || 呼び出し元にデータをマーシャリングして戻すことを示す。 | |||
|} | |||
</center> | |||
<br> | |||
<source lang="csharp"> | |||
void Method([in] int[] array); | |||
</source> | |||
<br><br> | <br><br> | ||