This category contains 35 posts

An Unmanaged Implementation of the IList Interface Part 1

1. Introduction 1.1 In this multi-part post, I will present an implementation of the .Net IList interface using unmanaged code. 1.2 Specifically, I shall be coding in C++ using ATL. 1.3 In this part 1, I will show how to use several STL classes and techniques to provide the functionality of IList. 1.4 Another important … Continue reading

Understanding Implementations for ITypeLibExporterNotifySink Part 1.

1. Introduction. 1.1 This article is a follow up to my last blog Programmatically Register Assemblies in C#. 1.2 In that article, I mentioned that I will be writing more to explain implementations for the ITypeLibExporterNotifySink interface as used in the context of a call to TypeLibConverter.ConvertAssemblyToTypeLib(). 1.3 I will dive straight into exploring this … Continue reading

Programmatically Register Assemblies in C#.

1. Introduction. 1.1 After publishing Programmatically Register COM Dlls in C# back in 2011, I received a number of requests for advise on how to register managed assemblies as COM servers. 1.2 In this blog, I will present the reader with a sample C# program that will perform such registration. 1.3 The sample assembly COM-registration … Continue reading

Replace all UUIDs in an ATL COM DLL.

1. Introduction. 1.1 Recently, a friend asked me for advise on a very unusual requirement. 1.2 He needs to replace all UUIDs in a COM DLL with new ones. 1.3 He does not have the source codes to the original COM server so any modifications will have to be done on the binary code. 1.4 … Continue reading

Tip for Managed Applications that use COM objects – Exposing Metadata For Your COM Objects Part 2

1. Introduction 1.1 This article is a continuation of a previous article in which I expounded on how metadata can be exposed to managed code for COM objects. 1.2 In that article, the COM object was created via ProgID through the use of the Type.GetTypeFromProgID() function followed by a call to Activator.CreateInstance(). 1.3 With a … Continue reading

Tip for Managed Applications that use COM objects – Exposing Metadata For Your COM Objects Part 1

1. Introduction. 1.1 If you have ever used COM objects in your managed applications, you would have certainly come across an intriguing  type named “System.__ComObject”. 1.2 This type indicates a generic Runtime-Callable Wrapper (RCW) that has no metadata available. It is also an internal class in the mscorlib assembly. It is not possible to define … Continue reading

How to Store Binary Data in a BSTR.

1. Introduction 1.1 A BSTR is flexible in the sense that not only can you store a character string in it, you can also store binary data. 1.2 This programming tip presents sample code which demonstrates how this can be done. 2. The SysAllocStringByteLen() API. 2.1 Normally, when you want to allocate a BSTR, you … 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

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

1. Introduction. 1.1 Singleton COM objects are guarenteed to be the only instances of coclasses. 1.2 However, what about their apartment ? Do they always run in the same apartment ? The answer depends on the apartment model that they use. 1.3 For MTA singleton objects : yes. They will always run in the one and only … Continue reading