Team LiB
Previous Section Next Section

COM Interop Rules and Facts

First, here are the most common causes of COM interop errors:

The following are rules and facts about COM interop:

Caution 

People often confuse the built-in C# operator sizeof and the Marshal.SizeOf functionality. sizeof returns the managed size of the type in bytes. Marshal. SizeOf returns the unmanaged size of a type in bytes.

Note 

In the single-threaded apartment (STA) model, [STAThread], one or more threads in a process use COM, and calls to COM objects are synchronized by COM. Interfaces are marshaled between threads. A degenerate case of the STA model, where only one thread in a given process uses COM, is called the single-threading model . In the multithreaded apartment (MTA) model, one or more threads use COM, and calls to COM objects associated with the MTA are made directly by all threads associated with the MTA, without any interposition of system code between caller and object. Because multiple simultaneous clients may be calling objects more or less simultaneously (simultaneously on multiprocessor systems), objects must synchronize their internal state by themselves. Interfaces are not marshaled between threads. Previous Microsoft documentation sometimes referred to the STA model simply as the apartment model and the MTA model as the free-threaded model .


Team LiB
Previous Section Next Section