Marshal class

zhaozj2021-02-16  59

Disclaimer: From MSDN 2005 Express, don't know right, Wahahaha

A series of methods for applying for non-accomplished memory, copy non-managed memory blocks, and translational translations into non-accomplished types and many of the non-accumulated code deal. (Non-managed memory looks so uncomfortable, how to say, memory is now managed by the garbage recycling mechanism; and non-contained, it is necessary to manually manage, these two differences, history The legacy issues have always been difficult to solve)

Namespace: system.Runtime.InteropServicesassembly: mscorlib (in mscorlib.dll)

prototype

Visual Basic

Notinheritable Mustinherit Public Class Marshal

C #

Public Sealed Abstract Class Marshal

C

Public __gc __sealed __ABSTRACT CLASS MARSHAL

JScript

Public Abstract Class Marshal

These static methods provided by the Marshal class are mainly used as the non-accomplished code. Most methods are advanced applications that make developers who need to establish bridges between managed and non-contained modules. For example, there is such a method StringTohglobalansi to read the string in a specified string instance (the string is in the managed bunch), then put into the non-contained buffer (the buffer is in the non-contained pile In the middle, the buffer is also assigned to a suitable size. The C # code is as follows:

String s = "hello";

INTPTR P = Marshal.StringTohglobalsi (s);

At this time, P can be considered a pointer to the "Hello" pointing to the ANSI string.

How does the Common Language Runtime provide a hash function. For more information, please refer to Interop Marshaling.

Marshal has many members, in order to better understand them, we divide members according to their use (software is used as this, I don't remember this sentence, I admit it a little).

category

member

Advanced Marshaling

advanced

(See if it is unable to divide this, MS also learns to sell self-selling)

GetManagedthunkforunmanageDmethodptr,

GetunmanagedthunkFormanageDmethodptr,

Numparambytes

COM Library Function

COM library function

(Don't think it is a serial port ...)

Bindtomoniker,

GetActiveObject

COM Utilities

COM related

ChangeWrapperHandleStrength, CreateWrapperOfType,

GetcomobjectData,

GetComslotFormethodinfo,

Getendcomslot,

GetMethodInfoforComslot, getStartComslot,

ReleaseComobject,

SetcomobjectData

Data Transformation

Data transfer / conversion

Managed to unmanaged: Copy, GetComInterfaceForObject, GetIDispatchForObject, GetIUnknownForObject, StringToBSTR, StringToCoTaskMemAnsi, StringToCoTaskMemAuto, StringToCoTaskMemUni, StringToHGlobalAnsi, StringToHGlobalAuto, StringToHGlobalUni, StructureToPtr, UnsafeAddrOfPinnedArrayElementUnmanaged to managed: Copy, GetObjectForIUnknown, GetObjectForNativeVariant, GetObjectsForNativeVariants, GetTypedObjectForIUnknown, GetTypeForITypeInfo, PtrToStringAnsi, PtrToStringAuto, PtrToStringBSTR, PTRTOStringuni

Properties: SystemDefaultcharsize, SystemMaxdbcscharsize, SYSTEMAXDBCS

Direct Reading and Writing

Access directly

Readbyte,

Readint16,

READINT32,

READINT64,

Readintptr,

Writebyte,

WriteInt16,

WriteInt32,

WriteInt64,

WriteInTr

Error Handling

Error handling

COM: gethrforexception, throwexceptionForhr

Win32: getlastwin32error, getExceptioncode, getExceptionPointers

Both: GethrforlastWin32error

Hosting Utilities

GetthreadfromfiberCookie

Iunknown

AddRef,

QueryInterface,

RELEASE

Memory Management

Memory management

COM: Alloccotaskmem, Realloccotaskmem, Freecotaskmem, FreeBSTR

Win32: Allochglobal, Reallochglobal, Freehglobal

Both: Destroystructure

Platform Invoke Utilities

Platform call

Prelink, Prelinkall, Gethinstance

Structure Inspection

Structural information

Offsetof, Sizeof

Type Information

Types of

GenerateGuidfortype,

GenerateProgidfortype,

GettypeInfoname,

GetTypelibguid,

GetTypelibguidForassembly,

GetTypeliblcid,

Gettypelibname,

IScomobject,

IStypevisibleFromcomcomcomcomcom

Inheritance level

System.Object

System.Runtime.InteropServices.Marshal

Thread security

Only some of the public static members can be a thread safe, while others cannot guarantee.

Development Platform

Windows 2000, And Windows XP Home Edition, Windows XP Professional, Windows Server 2003

NET Framework version support 1.1, 2.0

转载请注明原文地址:https://www.9cbs.com/read-18057.html

New Post(0)