//
archives

Archive for

Loading Parameters for a Managed COM Server in HTML.

1. Introduction. 1.1 ActiveX and COM objects may be loaded onto a HTML page via the <object> tag. 1.2 Additionally, parameters may be passed to the ActiveX/COM objects using the <param> tag (see HTML <param> Tag). 1.3 But what if the COM object is instantiated from a managed class exported by COM interop ? In this … Continue reading

Exposing an Enumerator from Managed Code to COM.

1. Introduction. 1.1 An enumerator allows iterations over an unordered collection of objects of a specific type. 1.2 In COM, enumerators are expressed as IEnumXXX interfaces (e.g. IEnumUnknown, IEnumBstr, IEnumVARIANT, etc). 1.3 This blog presents a simple way to expose an enumerator from managed code to COM. 2. Exposing an Enumerator to COM from a Managed … Continue reading

Quick Serialization/Deserialization of a Managed Structure.

1. Introduction. 1.1 Serialization/deserialization of some data structure is a common and useful programming requirement. 1.2 Serialized data may be transferred over a network to another machine to be deserialized back as a data structure. Or it may be saved to the disk for storage as part of the data file of an application. 1.3 … Continue reading

The Significance of the COM coclass.

1. Introduction. 1.1 Intermediate COM application developers generally understand the COM development process and are familiar with most of the ubiquitous terms, phrases and concepts, e.g. IUnknown, IDispatch, interfaces, reference counting, interface querying, registration, progID, events, etc. 1.2 The keyword “coclass”, however, remains mysterious and relatively misunderstood. The reason for this is probably due to its perceived lack … Continue reading

Obtain Type Information of IDispatch-Based COM Objects from Managed Code.

1. Introduction. 1.1 Twice this year, someone from the MSDN forum attempted to determine the names of methods exported from a COM object by using Type.GetMethods(). 1.2 This is possible if the type library of the COM object has been imported into the managed code project using TLBIMP.EXE (see section 2 below). 1.3 When a COM object is … Continue reading

Using the Mutex Class to Ensure Only One Instance of a Managed App Runs.

1. Introduction. 1.1 It is not uncommon to require that only one instance of a program be executable at any one time. 1.2 A common programming technique used to ensure this involves the use of a system-wide mutex object. 1.3 This blog provides a sample implementation of such a single-instance-only application and expounds on the … Continue reading

Minimizing the Console Window in C#.

1. Introduction. 1.1 A few days ago, I was developing a console application written in C#. 1.2 One of the requirements of this application was that it must immediately minimize the console window on startup. 1.3 For the benefit of readers, I decided to post here the code for minimizing the console window of a managed application. … Continue reading

Using Structured Exception Handling to Handle Exceptions from C++ in C#.

1. Introduction. 1.1 At some point, every developer who has ever worked with a mix of managed and unmanaged code would wonder whether it is possible to handle exceptions thrown from unmanaged code in managed code. 1.2 In this blog, I shall expound on one way this can be achieved. The unmanaged code that I shall use to … Continue reading

Using a VT_RECORD VARIANT in Managed Code Part 5

1. Introduction. 1.1 In part 4, I demonstrated how to receive a VT_RECORD VariantStructGeneric structure from an unmanaged API as an “out” parameter. 1.2 Here in part 5, I shall demonstrate how to pass a VT_RECORD VariantStructGeneric to and from an unmanaged API as both and “in” and “out” parameter (i.e. by reference parameter). 1.3 A structure … Continue reading

Using a VT_RECORD VARIANT in Managed Code Part 4

1. Introduction. 1.1 In part 3, I started to use the VariantStructGeneric structure to work with VT_RECORD VARIANTs in managed code. 1.2 We can see that the VariantStructGeneric structure completely replicates the unmanaged VARIANT structure and its use in managed code is intuitive for those who are familiar with VARIANTs. 1.3 In part 3, I demonstrated … Continue reading