//
archives

.NET

This tag is associated with 24 posts

Perform Custom Action during Registration of a Managed COM Server.

1. Introduction. 1.1 When a COM-visible managed class library is COM registered via regasm.exe, it is possible to perform various custom activities, e.g. adding additional registry keys/values. 1.2 In fact, just about anything can be performed, e.g. reading/writing data to a file, launch external processes, etc. 1.3 Then, if the class library is unregistered, reverse activities … Continue reading

Specifying Arrays in UDTs

1. Introduction. 1.1 Although COM User-Defined Types (UDTs) commonly use BSTRs to hold strings (i.e. character arrays) and SAFEARRAYs to hold arrays of other types, it is possible to define character arrays and arrays of other types inside a UDT. 1.2 This blog will demonstrate the use of arrays inside a UDT with an emphasis … Continue reading

RCW Internal Reference Count

1. Introduction. 1.1 The Runtime Callable Wrapper (RCW) is used to represent a COM object in the managed world. Internally a RCW contains a reference count on the COM object that it wraps. 1.2 Note that this reference count is not equivalent to the well-known COM reference count. The COM reference count is held within the … Continue reading

Misunderstanding IntPtr and System.Object.

1. Introduction. 1.1 Some time ago, someone from the MSDN forum asked for advise on a problem that he was facing. 1.2 He had created a COM interface that serves as a notifier of events. A receiver of the events must implement a notification method and then connect with the notification interface via a method that takes … Continue reading

Specifying SAFEARRAY parameters with COleDispatchDriver::InvokeHelper()

1. Introduction. 1.1 Recently, someone from the MSDN forum requested advise on a problem he faced while attempting to call a C# method (exposed as a COM method) from an unmanaged MFC application. 1.2 The C# method takes an array of integers by reference, e.g. : bool SetArray([In][Out] ref Int32[] integer_array); 1.3 His C# class is … Continue reading

Interoping COM Structures.

1. Introduction. 1.1 COM structures, or User-Defined Types (UDTs) are very useful constructs. Their interoperability in managed code, however, is not perfect and there are situations in which their use is not possible. 1.2 This blog examines various scenarios in which UDTs are used between COM and managed code (specifically C#). We will also analyze the success … Continue reading

Marshaling a SAFEARRAY of Managed Structures by COM Interop Part 2

1. Introduction. 1.1 In part 1 of this series of blogs, we studied how to pass a SAFEARRAY of UDTs (which originate from managed code) to an unmanaged client. 1.2 In this part 2, we shall be looking at how to pass a SAFEARRAY of UDTs from an unmanaged COM client application to a managed COM server. 2. … Continue reading

Marshaling a SAFEARRAY of Managed Structures by COM Interop Part 1

1. Introduction. 1.1 There are two basic ways to pass an array of managed structures to unmanaged code. These include : By C-style array. By SAFEARRAY. 1.2 In this series of blogs I shall expound on the use of SAFEARRAYs to pass an array of managed structures to unmanaged code. 1.3 In this part 1, I shall provide background information … Continue reading

Passing Managed Structures With Strings To Unmanaged Code Part 1

1. Introduction. 1.1 Managed structures that contain strings are a common sight. The trouble is that managed strings are non-blittable. This means that they do not have a single common representation in the unmanaged world. However, there are several standardized representations that are recognized by the CLR. 1.2 A managed string is also a referenced type which means … Continue reading

Misunderstanding IDL Parameter Direction Leading to BSTR Memory Leakage.

1. Introduction. 1.1 Just yesterday a Visual C# Forum Member posed an interesting question. The post can be found here : Possible BSTR memory leak 1.2 Basically, he designed a COM class (in IDL) that takes charge of acquiring data from some source. He also defined a callback interface that is to be implemented by clients. An instance … Continue reading