//
archives

Archive for

Why an ActiveX Control on a Managed Window Form Must Be STA-based.

1. Introduction. 1.1 A Managed Windows Form application may freely incorporate an ActiveX control on its window. 1.2 However, an important requirement is that the thread which creates the window (that contains the ActiveX control) must be an STA thread. 1.3 Otherwise, a System.Threading.ThreadStateException will be thrown with the following being a typical accompanying error message : An unhandled … Continue reading

Generic Helper Function for Creating SAFEARRAYs.

1. Introduction. 1.1 SAFEARRAYs are very useful objects in COM. They are containers for data. 1.2 SAFEARRAYs are also used for transporting arrays between managed and unmanaged code. 1.3 Although standard APIs are used to create and fill SAFEARRAYs, these APIs are not the easiest nor the most intuitive to use. Additional structures like SAFEARRAYBOUND nned to be understood … Continue reading

The STA Singleton COM Object – Problems and Solutions Part 2.

1. Introduction. 1.1 In part 1 of this series of articles, I explained the problem associated with a COM singleton coclass which is housed in an in-proc server (i.e. a DLL). 1.2 The way the COM sub-system instantiate coclasses is such that a singleton STA object can be legitimately accessed from multiple threads concurrently despite the built-in windows-message-based … Continue reading