Data types

The following table shows

Unmanaged Data Types Managed Data Type

Supply Data Receive Data

Pointer (Object reference, user data)GCHandle GCHandle

The GCHandle provides the primary means of passing an object references to unmanaged code, and ensuring garbage collection does not happen. A GCHandle needs to be allocated, and later freed when no longer needed. There are several types of GCHandle, GCHandleType.Normal being the most useful when an unmanaged client holds the only reference. In order pass a GCHandle to an API function once it is allocated, type cast it to IntPtr (and optionally onwards to LongInt, depending on the unmanaged declaration). The IntPtr can later be cast back to a GCHandle. Note that IsAllocated must be called before accessing the Target property, as shown below:

procedure MyProcedure; var

Ptr: IntPtr; Handle: GCHandle; begin if Ptr <> nil then begin

Handle := GCHandle(Ptr); if Handle.IsAllocated then DoSomething(Handle.Target);

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment