//
archives

UnmanagedType.LPStr

This tag is associated with 4 posts

Passing a Pointer to a Structure from C# to C++ Part 3.

1. Introduction. 1.1 In part 2 of this series of blogs, I have demonstrated how to marshal to unmanaged code a pointer to a structure which contains non-blittable field types. 1.2 We have examined how such a structure is to be allocated and deallocated in memory. We have seen in particular, the importance of using the Marshal.DestroyStructure() … Continue reading

Passing a Pointer to a Structure from C# to C++ Part 2.

1. Introduction. 1.1 In Passing a Pointer to a Structure from C# to C++ Part 1 I demonstrated the basic principles of marshaling a pointer to a structure from managed code (C#) to unmanaged code (C++). 1.2 In part 1, I used a simple managed structure with a single Int32 type member. The idea is to … 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

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