lect12 - Yin Lou CS 2026, Spring 2010 Garbage Collection...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Yin Lou CS 2026, Spring 2010 Garbage Collection Memory Allocation Algorithms P/Invoke CIL P/Invoke = Platform Invoke Allows managed code to call unmanaged functions in COM objects, C/C++ DLLs, etc. e.g. access to Win32 API To declare unmanaged functions Use DllImport attribute and static extern [DllImport (kernel32.dll)] static extern int GetProcessHeap() using System.Runtime.InteropServices; namespace HelloWorld { class MyClass { [DllImport (user32.dll, CharSet=CharSet.Ansi)] static extern int MessageBox(int hwnd, string msg, string caption, int t); public static void Main() { MessageBox(0 , Hello World!, Caption, 0 ); } } } Locates implementing DLL Loads DLL into memory Finds function address Pushes args on stack, marshalling data Transfers control to unmanaged code Unmanaged code can call back to managed code Unmanaged parameter is function pointer In managed code, must supply parameter as delegate P/Invoke creates callback thunk Passes address of thunk as callback parameters...
View Full Document

Page1 / 21

lect12 - Yin Lou CS 2026, Spring 2010 Garbage Collection...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online