Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The uppercase identifiers are macros, they ensure that the COM interface function has the proper signature. A COM function that's compatible with automation must use the correct calling convention, __stdcall, and must return a long (an hresult) that indicates the error or success status. Additional requirements are that the COM interface must implement IUnknown and that the function argument types should restrict themselves to automation compatible types.</p> <p>The COM interop support in the CLR ensures that these requirements are met. It generates a v-table for a C# interface that automatically implements IUnknown, you don't have to implement it yourself. The HRESULT return value is automatically generated, it is mapped from an Exception. Function arguments are automatically marshaled from their unmanaged type to the equivalent native type.</p> <p>The argument type translation is a rather large topic and covered in any decent book about the subject (like Adam Nathan's). Suffice it to say that any automation compatible type has a corresponding managed type. The harder ones are object to VARIANT, string to BSTR and array to SAFEARRAY.</p> <p>You use the [ComVisible] attribute in C# to create a COM server. Several other ones are relevant, like [Guid] and [InterfaceType]. This is well covered in any examples. You create the type library with Tlbexp.exe or, more commonly, with Regasm.exe /tlb. The latter tool is the one that's required to register the server, you cannot use Regsvr32.exe anymore.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload