Marshaling Data with Platform Invoke 之五 Miscellaneous Marshaling Samples(用时查阅)

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

posted on 2010-01-09 17:19  Acor  阅读(174)  评论(0编辑  收藏  举报

导航