C Sharp Programming/The .NET Framework/Marshalling

The .NET Framework currently supports calling unmanaged functions and using unmanaged data, a process called marshalling. This is often done to use Windows API functions and data structures, but can also be used with custom libraries.

GetSystemTimes
A simple example to start with is the Windows API function. It is declared as:

is a pointer to a structure, which is simply a 64-bit integer. Since C# supports 64-bit numbers through the type, we can use that. We can then import and use the function as follows:

Note that the use of or  in parameters automatically makes it a pointer to the unmanaged function.

GetProcessIoCounters
To pass pointers to structs, we can use the or  keyword: