Open class as STA COM

I have a C # class that I need to open as COM. A tool that will use a COM object requires STA support. Is there anything special I need to do with my COM object?

(I know about the STAThread attribute, but (if I'm not mistaken) This indicates that the .net thread should be compatible with the STA, and not to indicate that my COM object should be compatible).

Here is my declaration so far. Do you see anything I need to add?


    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [ComDefaultInterface(typeof(ITestClass1))]
    [Guid("093A3701-2C53-4A31-97C5-0F3C205E5B4C")]
    public class Class1: ITestClass1 {..}

    [ComVisible(true)]
    [Guid("8D52F785-CDD8-4248-8AB7-97B8C19DE59B")]
    public interface ITestClass1 {..}

+3
source share
2 answers

COM- ThreadingModel. Single threaded , "".

Regasm.exe "Both". , STA MTA. , .NET , , . , [ComRegisterFunction].

, "Both", . Thread.GetCurrentThread(). GetApartmentState(). MTA, , , . .NET- .

+6

. ComRegisterFunction, voodoo. , - , , STA, COM-, STA.

+1

Source: https://habr.com/ru/post/1755338/


All Articles