//
archives

managed

This tag is associated with 13 posts

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

Passing Managed Structures With Arrays To Unmanaged Code Part 2

1. Introduction. 1.1 In part 1 of this series of blogs, we discussed the techniques for passing by value a structure that contains an array. 1.2 In this part 2, we explore the various techniques for passing such a structure as a return (or “out”) parameter. In other words, how to receive an initialized structure from … Continue reading

Passing Managed Structures With Arrays To Unmanaged Code Part 1

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

Using BSTR in Managed Code Part 2

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

Using BSTR in Managed Code Part 1

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

Passing Multi-Dimensional Managed Array To C++ Part 2

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

Delegates As Callbacks Part 2

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

Delegates as Callbacks Part 1

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

Returning Strings from a C++ API to C#

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