This topic has not yet been rated - Rate this topic

Miscellaneous Marshaling Samples

Factors such as garbage collection and threading can impact the behavior of the interop marshaler. Further, subtle differences in programming and type models can make passing data to an unmanaged library confusing. This section provides a set of samples that address some of these differences.

The following table lists marshaling options for various types of items, describes their usage, and provides a link to the corresponding sample.

Type of item

Description

Sample

Function pointer

Passes a delegate to an unmanaged function that expects a function pointer.

Callback

HandleRef

Uses the HandleRef structure to prevent garbage collection.

HandleRef

LPARAM

Uses the GCHandle structure to pass a managed object to an unmanaged function that expects an LPARAM type.

GCHandle

Single-threaded apartment (STA)/multithreaded apartment (MTA)

Changes the default apartment settings when an unmanaged function calls CoInitialize.

ActiveDir

void*

Calls a function that has void* as a parameter.

Void

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.