//
archives

Managed Structures

This category contains 16 posts

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 7.

1. Introduction. 1.1 We have reached the most complex part of this series of articles on the use of SAFEARRAY to marshal arrays of managed structures between managed and unmanaged code. 1.2 I do hope that I have maintained the reader’s interest up to this point. 1.3 In the first 3 parts of this series, we … Continue reading

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 6.

1. Introduction. 1.1 Starting from part 4 I have started to discuss how to interop marshal a managed array of TestStructure structs that is contained within a structure. 1.2 We have seen in part 4 an example for marshaling such a container structure to unmanaged code “one way” (i.e. as an “in” parameter). 1.3 In part … Continue reading

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 5.

1. Introduction. 1.1 In part 4, I have started to discuss how to interop marshal a managed array that is contained within a structure. 1.2 I have given a specific working example for marshaling such a container structure to unmanaged code “one way” (i.e. as an “in” parameter). 1.3 Here in part 5, I shall demonstrate how to … Continue reading

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 4.

1. Introduction. 1.1 In parts 1 through 3 of this series of articles, I have thoroughly discussed the techniques for exchanging arrays between managed and unmanaged code by way of SAFEARRAYs. 1.2 The knowledge that can be gained from the first 3 parts of this series is sufficient for general development purposes. 1.3 From part 4 … Continue reading

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 3.

1. Introduction. 1.1 In part 1 of this series of articles, I demonstrated how to transfer managed arrays to unmanaged code as SAFEARRAYs. The transfer was single-directional “into” the unmanaged function and the SAFEARRAY that was passed to the unmanaged function is treated as “read-only”. 1.2 Then in part 2, I showed how to return a SAFEARRAY from … Continue reading

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 2.

1. Introduction. 1.1 In part 1 of this series of articles, I explained how managed arrays may be transferred to unmanaged code as a SAFEARRAY. 1.2 In part 1, the SAFEARRAY was passed to unmanaged code as an “in” (read-only) parameter. 1.3 Here in part 2, I shall continue the discussion this time with the aim of … Continue reading

Marshaling a SAFEARRAY of Managed Structures by P/Invoke Part 1.

1. Introduction. 1.1 I have previously written about exchanging SAFEARRAYs of managed structures with unmanaged code via COM interop. 1.2 In this new series of articles, I shall expound on the exchange of such SAFEARRAYs via P/Invoke. 1.3 I have arranged this series of articles into multiple parts. In the first 3 parts, I shall show … Continue reading

Passing Managed Structures With Strings To Unmanaged Code Part 3

1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (which contains strings) to unmanaged code. The structure was passed as an “in” (by-value) parameter, i.e. the structure was passed to the unmanaged code as a read-only parameter. 1.2 Then in part 2, we studied the techniques for receiving … Continue reading

Passing Managed Structures With Strings To Unmanaged Code Part 2

1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (which contains strings) to unmanaged code. The structure was passed as an “in” (by-value) parameter, i.e. the structure was passed to the unmanaged code as a read-only parameter. 1.2 Here in part 2, we shall explore the … Continue reading

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