To correctly expose Java objects to COM and COM objects to Java, the virtual machine uses attributes in the Java class file that give information about COM parameter types, COM method vtable offsets, COM struct field offsets, and so on.
The Microsoft SDK for Java contains the header file comattr.h, which defines the layouts and valid values of the attributes. This reference describes the class file attributes that must be in any class file that invokes a COM object from Java or exposes a Java object as a COM object.
This reference contains the following topics.
ActualAccessFlags implements the protection rules for inner and nested classes.
COM_Class_Type pertains to the class level and denotes the implementation language. It indicates that a Java class is to be used as a native structure, COM interface, or COM object.
COM_CustData pertains to the class level. It stores type library custom data (CUSTDATA) for a Java class.
COM_ExposedAs_Group pertains to the method level. It exposes a Java method to COM and prescribes the external interface (vtable or dispatch) of a COM-Callable wrapper created for a Java object.
COM_GuidPool pertains to the class level. It stores the class IDs (CLSIDs) and interface IDs (IIDs) that are referenced by index from other attributes in the class.
COM_MapsTo pertains to the field level. It exposes external data to Java, providing type and layout information about each field in a COM class.
COM_MethodPool pertains to the class level. It stores distilled type library information about the COM methods that are invoked and implemented by the Java methods in the Java class file.
COM_ProxiesTo pertains to the method level. It exposes a COM method to Java.
COM_Register stores data for registering a class as a COM coclass.
COM_Safety indicates that a COM class can safely be used by an untrusted class.
Delegate specifies that a class is a delegate type and will be used for method invocations, or that a method is an invocation method.
JITMeNot specifies that a method or the class's static initializer should not be JIT-compiled.
LinkSafe specifies that a class is accessible to untrusted classes.
LinkUnsafe specifies that a class is not accessible to untrusted classes.
MulticastDelegate specifies that a method is to be treated as a multicast invocation method by the Microsoft VM.
NAT_L specifies the DLL name and DLL entry point (method) name associated with a J/Direct Java method.
NAT_L_DCTS specifies that no extra call-time security checks are required when a J/Direct method is called.
SecurityAPI specifies that a method requires additional space in its stack frame. The extra frame space is used to store security information at runtime.
SourceDir specifies the source directory of the Java source file for this class.
The attributes in the following table are for backward compatibility with older Java compilers, and are not documented here.
Old classes, methods, and fields | New attributes |
Microsoft_COM_Class_Type (Class) | COM_Class_Type |
Microsoft_COM_ExposedAs_Group (Method) | COM_ExposedAs_Group |
Microsoft_COM_GuidPool (Class) | COM_GuidPool |
Microsoft_COM_MapsTo (Field) | COM_MapsTo |
Microsoft_COM_MethodPool (Class) | COM_MethodPool |
Microsoft_COM_ProxiesTo (Method) | COM_ProxiesTo |
Microsoft_COM_Safety (Class) | COM_Safety |
Note that the attributes specify detail at the method level whenever possible. That is, while you customarily think of interfaces having IIDs, the attribute specification specifies an iid for each method, so that one Java interface could conceivably proxy to methods on multiple IIDs.
Unless otherwise noted, successive items in an attribute structure are stored sequentially in a Java class file. There is no padding between or after attribute fields. Any required padding will be declared explicitly as unused fields. Data items that use multiple bytes are always stored in big-endian order (high bytes first) unless otherwise specified. Several data types are used in a Java class file. These data types include u1, u2, and u4, which represent an unsigned one-, two-, or four-byte quantity. A standard 6-byte attribute_info structure (the header for every attribute) exists for all Java class attributes.
The following table shows C/C++ data types that are used to describe attributes.
C/C++ data type | Java data type | Description and representation |
BYTE | u1 | One unsigned byte. |
WORD | u2 | Two unsigned bytes (big endian). |
DWORD | u4 | Four unsigned bytes (big endian). |
In terms of alignment, there is no implicit padding between structure fields or after the last structure field.
All unused bits in Flag fields must be zero.
Several of these attributes use the equivalent of C/C++ structures or unions. These are as follows.
Structures Used by Attributes | Applies to | Comments |
MCCustomMethod | COM_MethodPool | Used to describe a method that is custom-marshaled. |
MCSpecialArgumentEntry | COM_MethodPool | Used to describe the arguments to a custom-marshaled method. |
MCDispMethod | COM_MethodPool | Used to describe a dispatch method. |
MCExposedAs | COM_ExposedAs_Group | Used to expose a Java method as a COM method. |
MCFuncDesc | COM_MethodPool | A general structure used to describe any method type. |
MCTypeDesc | COM_MapsTo, COM_MethodPool | Used to describe the type of a single field in a class or a single argument and return type of a vtable method. |
MCVarTypeDesc | COM_MethodPool | Used to describe the type of a single parameter or return value to an IDispatch method. |
MCVtblMethod | COM_MethodPool | A structure used to describe a vtable method. |
Integrating Java and COM (programmer's guide)
Using COM Objects from Java (white paper)
Integrating Java and COM (white paper)