1. Introduction 1.1 Managed structures that contain arrays are a common requirement in .NET development. Such structures, however, cannot be conveniently passed to unmanaged code. This is because arrays are referenced types and are not blittable. And because arrays are not blittable, the containing structure is also non-blittable. 1.2 This series of blogs will explore how managed structures … Continue reading
1. Introduction. 1.1 In part 1 of this series of blogs, I demonstrated how to use BSTRs in managed code complete with example codes that focuses on passing BSTRs from managed code to unmanaged code. 1.2 In this part 2, I shall provide example codes that demonstrate the receiving of BSTRs from unmanaged code. 1.3 … Continue reading
1. Introduction. 1.1 The COM BSTR may be used within managed code for various purposes including the exchanging of strings to and from unmanaged code. 1.2 There are several ways to work with BSTRs and these are listed in summary below : Using Marshal Class methods (e.g. Marshal.PtrToStringBSTR(), Marshal.StringToBSTR(), Marshal.FreeBSTR()). Using Unmanaged APIs (e.g. SysAllocString(), SysFreeString(), etc). … Continue reading
1. Introduction. 1.1 This blog forms part 2 of a series of blogs which explores techniques for passing multi-dimensional managed arrays to C++ applications. 1.2 We saw in part 1 how the distinctive feature of the layout of a C/C++ array enabled the seamless access of the data of a multi-dimensional managed array from a C++ program. Cool. 1.3 In … Continue reading
1. Introduction. 1.1 Multi-dimensional arrays, when exchanged between managed and unmanaged code, form an interesting subject. It is technically possible to achieve this but a good understanding of how managed and unmanaged arrays are organized is crucial in ensuring successful interop transfer. 1.2 In this series of blogs, we shall discuss how managed arrays can be exchanged between … Continue reading
1. Introduction. 1.1 This blog is a continuation of an earlier blog Delegates As Callbacks Part 1. 1.2 In this part 2, I shall demonstrate using managed methods as callbacks that can be invoked from unmanaged code. 2. Sample Code. 2.1 Listed below is a sample unmanaged code written in C++ : typedef void (__stdcall … Continue reading
1. Introduction 1.1 A concept frequently used in real-world software development is that of a callback. 1.2 A callback, as we know, is a function which is asynchronously called, often when some event of significance occurs. 1.3 This series of blogs examines how this concept is realized between managed and unmanaged code. In this part … Continue reading
1. Introduction. 1.1 Recently, someone from the MSDN forum presented a very interesting question. 1.2 He wrote a simple C# class which is COM exported. When he instantiated one such a managed class in an unmanaged C++ application, he noticed that there were two COM-Callable Wrappers created in the application. One for the exported C# class … Continue reading
1. Introduction. 1.1 APIs that return strings are very common. However, the internal nature of such APIs, as well as the use of such APIs in managed code, require special attention. This blog will demonstrate both concerns. 1.2 I will present several techniques for returning an unmanaged string to managed code. But before that I shall first provide an … Continue reading
1. Introduction. 1.1 Just today someone from the MSDN Common Language Runtime Forum asked a question about writing an API that can be called in C# to return a C++ class. 1.2 First of all, it must be noted that it is not possible to use an unmanaged class (e.g. a C++ class) in managed code (e.g. … Continue reading