In this article, a discussion of several new operating system integration features in Silverlight 5 including: P/Invoke, Multiple Windows and Unrestricted File System Access in Full Trust. Please review the Roadmap for the series before going any further.
The Roadmap for this Series
Included, the Roadmap for the series below as you may want to visit other sections as you learn Silverlight 5. I picked the following features as I thought that you may find them useful in your day-to-day work. If you want a specific topic covered then please leave it in the comments below.
- Introduction to SL5 – provides a brief history of Silverlight and relevant links.
- Binding - Ancestor Relative Source Binding and Implicit Data Templates.
- Graphics - XNA 3D API and Improved Graphics Stack.
- Media - Low-Latency Sound using XNA and Remote Control and Media Command (Keys) Support.
- Text - Text Tracking and Leading, Linked and Multi-column Text, OpenType Support, Pixel Snapped Text and TextOptions.
- Operating System Integration Part 1 - [This Post] - P/Invoke, Multiple Windows and Unrestricted File System Access in Full Trust.
- Operating System Integration Part 2 - Default Filename for SaveFileDialog, 64-bit browser support and Power Awareness.
- Productivity and Performance - XAML Binding Debugging, Parser Performance Improvements and Multi-core JIT for improved start-up time.
- Controls - Double and Triple click support, PivotViewer and ComboBox Type-Ahead.
- Other items - In-Browser HTML, PostScript and Tasks for TPL.
P/Invoke or Platform Invocation
Before we dive into an example. Let’s first answer the question, What is it? Platform Invocation Services, commonly referred to as P/Invoke, is a feature of Common Language Infrastructure implementations, like Microsoft's Common Language Runtime, that enables managed code to call native code.
*Reference to Wiki
This feature is new to Silverlight 5 and we will take a look at how to use it in your own applications.
In order to create a new P/Invoke application in Silverlight 5, we will need to enable “Require elevated trust” in Silverlight 5. We can also use the functionality in-browser or out-of-browser. Let’s begin.