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. |
|
Uses the HandleRef structure to prevent garbage collection. |
||
LPARAM |
Uses the GCHandle structure to pass a managed object to an unmanaged function that expects an LPARAM type. |
|
Single-threaded apartment (STA)/multithreaded apartment (MTA) |
Changes the default apartment settings when an unmanaged function calls CoInitialize. |
|
void* |
Calls a function that has void* as a parameter. |
See Also
Concepts
Marshaling Classes, Structures, and Unions