UnmanagedType 列挙体
アセンブリ: mscorlib (mscorlib.dll 内)
構文
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Enumeration UnmanagedType
System.Runtime.InteropServices.MarshalAsAttribute を設定した UnmanagedType 列挙体を使用して、アンマネージ コードとの相互運用時に型をどのようにマーシャリングするかを指定します。この列挙体を使用すると、単純値型 (I1、I2、I4、I8、R4、R8、U2、U4、U8)、.NET Framework で使用できないアンマネージ型などのさまざまな型を使用してコードをマーシャリングできます。
詳細については、「アンマネージ コードとの相互運用」を参照してください。
次のコード片では、COM コンポーネントによって実装されるアンマネージ インターフェイスをマネージ ソース コードで宣言する方法を示します。System.Runtime.InteropServices.ComImportAttribute は、IMyStorage インターフェイスが逆にエクスポートされて COM から使用されることを防ぎます (COM クライアントは、既存の COM コンポーネントを直接使用する必要があります)。この例では、MarshalAsAttribute によって複数の UnmanagedType メンバが指定されます。これらは、元の COM インターフェイスで使用される型を表します。
Imports System Imports System.Runtime.InteropServices Module MyModule ' If you do not have a type library for an interface ' you can redeclare it using ComImportAttribute. ' This is how the interface would look in an idl file. '[ 'object, 'uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"), 'dual, helpstring("IMyStorage Interface"), 'pointer_default(unique) '] 'interface IMyStorage : IDispatch '{ ' [id(1)] ' HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem); ' [id(2)] ' HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems); ' [id(3)] ' HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems); ' [id(4), propget] ' HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty); '}; ' This is the managed declaration. <ComImport(), Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")> _ Public Interface IMyStorage <DispId(1)> _ Function GetItem(<InAttribute(), MarshalAs(UnmanagedType.BStr)> ByVal bstrName As String) _ As <MarshalAs(UnmanagedType.Interface)> Object <DispId(2)> _ Function GetItems(<InAttribute(), MarshalAs(UnmanagedType.BStr)> ByVal bstrLocation As String, _ <OutAttribute(), MarshalAs(UnmanagedType.SafeArray)> ByVal Items() As Object) <DispId(3)> _ Function GetItemDescriptions(<InAttribute()> ByVal bstrLocation As String, _ <InAttribute(), OutAttribute(), MarshalAs(UnmanagedType.SafeArray)> ByRef varDescriptions() As Object) <DispId(4)> _ ReadOnly Property IsEmpty(<MarshalAs(UnmanagedType.VariantBool)> ByVal bEmpty As Boolean) End Interface End Module
using System; using System.Runtime.InteropServices; namespace MyModule { // If you do not have a type library for an interface // you can redeclare it using ComImportAttribute. // This is how the interface would look in an idl file. //[ //object, //uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"), //dual, helpstring("IMyStorage Interface"), //pointer_default(unique) //] //interface IMyStorage : IDispatch //{ // [id(1)] // HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem); // [id(2)] // HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems); // [id(3)] // HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems); // [id(4), propget] // HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty); //}; // This is the managed declaration. [ComImport] [Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")] public interface IMyStorage { [DispId(1)] [return : MarshalAs( UnmanagedType.Interface )] Object GetItem( [In, MarshalAs( UnmanagedType.BStr )] String bstrName ); [DispId(2)] void GetItems( [In, MarshalAs( UnmanagedType.BStr )] String bstrLocation, [Out, MarshalAs( UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT )] out Object[] Items ); [DispId(3)] void GetItemDescriptions( [In] String bstrLocation, [In, Out, MarshalAs( UnmanagedType.SafeArray )] ref Object[] varDescriptions ); bool IsEmpty { [DispId(4)] [return : MarshalAs( UnmanagedType.VariantBool )] get; } } }
using namespace System; using namespace System::Runtime::InteropServices; // If you do not have a type library for an interface // you can redeclare it using ComImportAttribute. // This is how the interface would look in an idl file. //[ //object, //uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"), //dual, helpstring("IMyStorage Interface"), //pointer_default(unique) //] //interface IMyStorage : IDispatch //{ // [id(1)] // HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem); // [id(2)] // HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems); // [id(3)] // HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems); // [id(4), propget] // HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty); //}; // This is the managed declaration. [ComImport] [Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26")] interface class IMyStorage { [DispId(1)] Object^ GetItem( [In,MarshalAs(UnmanagedType::BStr)]String^ bstrName ); //[return : MarshalAs(UnmanagedType::Interface)] [DispId(2)] void GetItems( [In,MarshalAs(UnmanagedType::BStr)]String^ bstrLocation, [Out,MarshalAs(UnmanagedType::SafeArray, SafeArraySubType=VarEnum::VT_VARIANT)]array<Object^>^Items ); [DispId(3)] void GetItemDescriptions( [In]String^ bstrLocation, [In,Out,MarshalAs(UnmanagedType::SafeArray)]array<Object^>^varDescriptions ); property bool IsEmpty { [DispId(4)] [returnvalue:MarshalAs(UnmanagedType::VariantBool)] bool get(); } };
import System.*; import System.Runtime.InteropServices.*; // If you do not have a type library for an interface // you can redeclare it using ComImportAttribute. // This is how the interface would look in an idl file. // [ // object, // uuid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26"), // dual, helpstring("IMyStorage Interface"), // pointer_default(unique) // ] // interface IMyStorage : IDispatch // { // [id(1)] // HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem); // [id(2)] // HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems); // [id(3)] // HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems); // [id(4), propget] // HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty); // }; // This is the managed declaration. /** @attribute ComImport() */ /** @attribute Guid("73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26") */ public interface IMyStorage { /** @attribute DispId(1) */ Object GetItem( /** @attribute In() @attribute MarshalAs(UnmanagedType.BStr) */String bstrName); /** @attribute DispId(2) */ void GetItems( /** @attribute In() @attribute MarshalAs(UnmanagedType.BStr) */String bstrLocation, /** @attribute Out() @attribute MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT) */Object Items[]); /** @attribute DispId(3) */ void GetItemDescriptions( /** @attribute In() */String bstrLocation, /** @attribute In() @attribute Out() @attribute MarshalAs(UnmanagedType.SafeArray) */Object varDescriptions[]); /** @attribute DispId(4) */ /** @return MarshalAs(UnmanagedType.VariantBool) */ boolean get_IsEmpty(); } //IMyStorage
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Weblioに収録されているすべての辞書からUnmanagedType 列挙体を検索する場合は、下記のリンクをクリックしてください。
全ての辞書からUnmanagedType 列挙体を検索
- UnmanagedType 列挙体のページへのリンク