Skip to main content

Posts

Showing posts with the label Platform Invoke (P-Invoke).

Using Unmanaged Code

Namespace: System.Runtime.InteropServices As not all the Windows APIs have been wrapped in .Net framework, one should be able to know who to interact with underlying operating system. Calling Platform Invoke: To call an unmanaged Windows API that is not wrapped in .Net Framework, P/Invoke is the only viable solution. There are three typical requirements that intend to use P/Invoke: 1.        Functionality Specific to OS, Context Switching, and File/IO 2.        Advanced manipulation of windows, menu, dialogs etc. 3.        Advanced and fast drawing features Use the syntax: [DllImport(“user32.dll”)] private static extern Int32 GetWindowsText(IntPtr hWnd, StringBuilder textValue, Int32 Count) Use StringBuilder instead of String when calling P/Invokes. Encapsulating DLL Functions : Try to Encapsulate the P/Invokes in a specialized class, so that one can us...