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 |
See Also
Marshaling Data with Platform Invoke | Platform Invoke Data Types | Marshaling Strings | Marshaling Classes, Structures, and Unions | Marshaling Arrays of Types