//
archives

Archive for

Tip for Supporting COM Events from a Managed Class : Use DispIds for Event Methods.

1. Introduction. 1.1 I had earlier published Supporting COM Events from a Managed Class. The aim of that article was to impart concise knowledge on how to support COM connection point protocol-based events from a managed class. A set of startup code was also provided for the reader to use as a template. 1.2 This … Continue reading

Handling .NET Events in Unmanaged Code using Event Accessors.

1. Introduction. 1.1 In the .NET framework, events are activated and handled using the event-delegate model. 1.2 Such a system is alien to unmanaged code. 1.3 However, there are ways to bridge .NET events to the unmanaged world. COM interop (via the use of the ComSourceInterfacesAttribute) being the conventional way. 1.4 The specific technique used is the COM connection … Continue reading

Tip for Supporting COM Events from a Managed Class : Hide Declaration of Event Members.

1. Introduction. 1.1 I had earlier published Supporting COM Events from a Managed Class. The aim of that article was to impart concise knowledge on how to support COM connection point protocol-based events from a managed class. A set of startup code was also provided for the reader to use as a template. 1.2 This write-up is one of several follow-up articles … Continue reading

Supporting COM Events from a Managed Class.

1. Introduction. 1.1 A COM-visible managed class can support COM events just like any COM coclass. 1.2 In this article, I aim to briefly expound on the .NET and COM event models and then zoom in on a working example which I hope will serve as a template for more complex systems, 1.3 In subsequent blog entries, I will also … Continue reading

Writing to Data Exported From a DLL in Managed Code.

1. Introduction. 1.1 This article is a direct follow-up from my last blog entry Accessing Exported Data From a DLL in Managed Code in which I expounded on the basic principles behind how to access data items exported from a DLL. 1.2 In that article, I wrote that besides being able to read them, it is … Continue reading

Accessing Exported Data From a DLL in Managed Code.

1. Introduction. 1.1 As we all know, exported functions from a DLL can be imported into managed code and invoked at runtime. 1.2 The System.Runtime.InteropServices.DllImportAttribute is used to declare such APIs. 1.3 But how about data exported from DLLs ?  In a C++ application, these global expirted data are usually imported by using an import library. Can … Continue reading

How to Determine if a Type Library was Generated from a .NET assembly.

1. Introduction. 1.1 When a .NET assembly (DLL or EXE) that contains a COM-visible class is compiled and registered via REGASM.EXE, a type library will be generated. 1.2 A type library may also be generated directly via TLBEXP.EXE. 1.3 The fact that this type library was generated from a managed source can be detected. 1.4 … Continue reading

How to Determine if a coclass is a Managed Class.

1. Introduction. 1.1 A managed class, when exported to COM, can be identified as being managed. 1.2 This is possible because the type library exporter, which handles the creation of the type library for the managed class library, will insert a special custom IDL attribute for the resulting coclass that represents the managed class. 1.3 This … Continue reading

Setting a Property by IDispatch Invoke.

1. Introduction. 1.1 When setting the property of a COM object via IDispatch::Invoke() using DISPATCH_PROPERTYPUT, it is important to ensure the following : DISPPARAMS.rgdispidNamedArgs must point to a DISPID whose value is DISPID_PROPERTYPUT (-3). DISPPARAMS.cNamedArgs must be equal to 1. 1.2 If the above settings are not done, IDispatch::Invoke() will return DISP_E_PARAMNOTFOUND. 1.3 This blog will demonstrate this … Continue reading

Using the StringBuilder in Unmanaged API Calls.

1. Introduction. 1.1 I have written extensively about passing strings to and from unmanaged APIs. Most notably Returning Strings from a C++ API to C#. 1.2 The managed type that I have used throughout these articles have been the string. 1.3 When working with unmanaged APIs the DllImport declarations of which take a string as parameter, one of … Continue reading