[ Pobierz całość w formacie PDF ]

public class COMVisibilityAttribute: System.Attribute
{
public COMVisibilityAttribute(System.Interop.ComVisibility value) {& }
public ComVisibilityAttribute Value { get {& } }
}
20.1.4 The DispId attribute
The DispId attribute is used to specify an OLE Automation DISPID. (A DISPID is an integral value that
identifies a member in a dispinterface.)
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field |
AttributeTargets.Property)]
public class DispIdAttribute: System.Attribute
{
public DispIdAttribute(int value) {& }
public int Value { get {& } }
}
20.1.5 The DllImport attribute
The DllImport attribute is used to specify the dll location that contains the implementation of an extern
method.
[AttributeUsage(AttributeTargets.Method)]
public class DllImportAttribute: System.Attribute
{
public DllImportAttribute(string dllName) {& }
public CallingConvention CallingConvention;
public CharSet CharSet;
public string DllName { get {& } }
public string EntryPoint;
public bool ExactSpelling;
public bool SetLastError;
}
Specifically, the DllImport attribute has the following behaviors:
" It can only be placed on method declarations.
" It has a single positional parameter: a dllName parameter that specifies name of the dll in which the
imported method can be found.
" It has four named parameters:
" The CallingConvention parameter indicates the calling convention for the entry point. If no
CallingConvention is specified, a default of CallingConvention.WinAPI is used.
" The CharSet parameter indicates the character set used in the entry point. If no CharSet is specified, a
default of CharSet.Auto is used.
" The EntryPoint parameter gives the name of the entry point in the dll. If no EntryPoint is
specified, then the name of the method itself is used.
" The ExactSpelling parameter indicates whether EntryPoint must exactly match the spelling of the
indicated entry point. If no ExactSpelling is specified, a default of false is used.
256 Copyright Microsoft Corporation 1999-2000. All Rights Reserved.
Chapter 20 Interoperability
" The SetLastError parameter indicates whether the method preserves the Win32 "last error". If no
SetLastError is specified, a default of false is used.
" It is a single-use attribute class.
In addition, a method that is decorated with the DllImport attribute must have the extern modifier.
20.1.6 The GlobalObject attribute
The presence of the GlobalObject attribute specifies that a class is a "global" or "appobject" class in COM.
[AttributeUsage(AttributeTargets.Class)]
public class GlobalObjectAttribute: System.Attribute
{
public GlobalObjectAttribute() {& }
}
20.1.7 The Guid attribute
The Guid attribute is used to specify a globally unique identifier (GUID) for a class or an interface. This
information is primarily useful for interoperability between the .NET runtime and COM.
[AttributeUsage(AttributeTargets.Class
| AttributeTargets.Interface
| AttributeTargets.Enum
| AttributeTargets.Delegate
| AttributeTargets.Struct)]
public class GuidAttribute: System.Attribute
{
public GuidAttribute(string uuid) {& }
public Guid Value { get {& } }
}
The format of the positional string argument is verified at compile-time. It is an error to specify a string
argument that is not a syntactically valid GUID.
20.1.8 The HasDefaultInterface attribute
If present, the HasDefaultInterface attribute indicates that a class has a default interface.
[AttributeUsage(AttributeTargets.Class)]
public class HasDefaultInterfaceAttribute: System.Attribute
{
public HasDefaultInterfaceAttribute() {& }
}
20.1.9 The ImportedFromCOM attribute
The ImportedFromCOM attribute is used to specify that a module was imported from a COM type library.
[AttributeUsage(AttributeTargets.Module)]
public class ImportedFromCOMAttribute: System.Attribute
{
public ImportedFromCOMAttribute(string value) {& }
public string Value { get {..} }
}
20.1.10 The In and Out attributes
The In and Out attributes are used to provide custom marshalling information for parameters. All combinations
of these marshalling attributes are permitted.
Copyright Microsoft Corporation 1999-2000. All Rights Reserved. 257
C# LANGUAGE REFERENCE
[AttributeUsage(AttributeTargets.Parameter)]
public class InAttribute: System.Attribute
{
public InAttribute() {& }
}
[AttributeUsage(AttributeTargets.Parameter)]
public class OutAttribute: System.Attribute
{
public OutAttribute() {& }
}
If a parameter is not decorated with either marshalling attribute, then it is marshalled based on the its parameter-
modifiers, as follows. If the parameter has no modifiers then the marshalling is [In]. If the parameter has the
ref modifier then the marshalling is [In, Out]. If the parameter has the out modifier then the marshalling is
[Out].
Note that out is a keyword, and Out is an attribute. The example
class Class1
{
void M([Out] out int i) {
&
}
}
shows that the use of out as a parameter-modifier and the use of Out in an attribute.
20.1.11 The InterfaceType attribute
When placed on an interface, the InterfaceType attribute specifies the manner in which the interface is
treated in COM.
[AttributeUsage(AttributeTargets.Interface)]
public class InterfaceTypeAttribute: System.Attribute
{
public InterfaceTypeAttribute(System.Interop.ComInterfaceType value)
{& }
public System.Interop.ComInterfaceType Value { get {& } }
}
20.1.12 The IsCOMRegisterFunction attribute
The presence of the IsCOMRegisterFunction attribute on a method indicates that the method should be
called during the COM registration process.
[AttributeUsage(AttributeTargets.Method)]
public class IsCOMRegisterFunctionAttribute: System.Attribute
{
public IsComRegisterFunctionAttribute() {& }
}
20.1.13 The Marshal attribute
The Marshal attribute is used to describe the marshalling format for a field, method, or parameter.
[AttributeUsage(AttributeTargets.Method |
AttributeTargets.Parameter |
AttributeTargets.Field)]
public class MarshalAttribute: System.Attribute
{
public MarshalAttribute(UnmanagedType type) {& }
public string Cookie;
258 Copyright Microsoft Corporation 1999-2000. All Rights Reserved.
Chapter 20 Interoperability
public Guid IID;
public Type Marshaler;
public UnmanagedType NativeType { get {& } }
public int Size;
public UnmanagedType SubType;
}
The Marshal attribute has the following behaviors:
" It can only be placed on field declarations, method declarations, and formal parameters.
" It has a single positional parameter of type UnmanagedType.
" It has five named parameters. [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • annablack.xlx.pl
  •