Compartir a través de


Enumeración VarEnum

 

Publicado: octubre de 2016

Indica cómo calcular las referencias de los elementos de matriz cuando se calcula una matriz desde código administrado a código no administrado como un UnmanagedType.SafeArray.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Sintaxis

[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum VarEnum
[SerializableAttribute]
[ComVisibleAttribute(true)]
public enum class VarEnum
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type VarEnum
<SerializableAttribute>
<ComVisibleAttribute(True)>
Public Enumeration VarEnum

Miembros

Nombre de miembro Descripción
VT_ARRAY

Indica un SAFEARRAY puntero.

VT_BLOB

Indica el número de bytes de longitud fija.

VT_BLOB_OBJECT

Indica que un objeto binario contiene un objeto.

VT_BOOL

Indica un valor booleano.

VT_BSTR

Indica una cadena BSTR.

VT_BYREF

Indica que un valor es una referencia.

VT_CARRAY

Indica una matriz de estilo C.

VT_CF

Indica el formato del Portapapeles.

VT_CLSID

Indica un identificador de clase.

VT_CY

Indica un valor de moneda.

VT_DATE

Indica un valor de fecha.

VT_DECIMAL

Indica un decimal valor.

VT_DISPATCH

Indica un IDispatch puntero.

VT_EMPTY

Indica que no se ha especificado un valor.

VT_ERROR

Indica un SCODE.

VT_FILETIME

Indica un valor FILETIME.

VT_HRESULT

Indica un valor HRESULT.

VT_I1

Indica un char valor.

VT_I2

Indica un short entero.

VT_I4

Indica un long entero.

VT_I8

Indica un entero de 64 bits.

VT_INT

Indica un valor entero.

VT_LPSTR

Indica una cadena terminada en null.

VT_LPWSTR

Indica una cadena grande terminada por null.

VT_NULL

Indica un valor null, similar a un valor null en SQL.

VT_PTR

Indica un tipo de puntero.

VT_R4

Indica un float valor.

VT_R8

Indica un double valor.

VT_RECORD

Indica un tipo definido por el usuario.

VT_SAFEARRAY

Indica una SAFEARRAY. No es válido en una variante.

VT_STORAGE

Indica que el nombre de un almacenamiento sigue.

VT_STORED_OBJECT

Indica que un almacenamiento contiene un objeto.

VT_STREAM

Indica que sigue el nombre de una secuencia.

VT_STREAMED_OBJECT

Indica que una secuencia contiene un objeto.

VT_UI1

Indica un byte.

VT_UI2

Indica un unsignedshort.

VT_UI4

Indica un unsignedlong.

VT_UI8

Indica un entero de 64 bits sin signo.

VT_UINT

Indica un unsigned valor entero.

VT_UNKNOWN

Indica un IUnknown puntero.

VT_USERDEFINED

Indica un tipo definido por el usuario.

VT_VARIANT

Indica una variante far puntero.

VT_VECTOR

Indica una matriz simple y contada.

VT_VOID

Indica un estilo de C void.

Comentarios

Se utiliza con System.Runtime.InteropServices.MarshalAsAttribute para controlar explícitamente el tipo de elemento de la SafeArray.

Ejemplos

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;
        }
    }
}
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, SafeArraySubType := VarEnum.VT_VARIANT)> _
                                      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 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();
   }
};

Información de versión

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Windows Phone
Disponible desde 8.1

Ver también

SafeArray
MarshalAsAttribute
Espacio de nombres System.Runtime.InteropServices

Volver al principio