DllImport "avicap32.dll" static extern int string int int int int int int int DllImport "avicap32.dll" static extern bool int MarshalAs UnmanagedType int MarshalAs UnmanagedType int // more and more of the same "capCreateCaptureWindow" ref string ref string.

Download Report

Transcript DllImport "avicap32.dll" static extern int string int int int int int int int DllImport "avicap32.dll" static extern bool int MarshalAs UnmanagedType int MarshalAs UnmanagedType int // more and more of the same "capCreateCaptureWindow" ref string ref string.

DllImport "avicap32.dll"
static extern int
string
int
int
int
int
int
int
int
DllImport "avicap32.dll"
static extern bool
int
MarshalAs UnmanagedType
int
MarshalAs UnmanagedType
int
// more and more of the same
"capCreateCaptureWindow"
ref string
ref string
Your Managed
Code
Manually
Generated
Interop Code
Traditional
Windows API
using Windows.Media.Capture;
var
new CameraCaptureUI
new Size
var
await
CameraCaptureUIMode
if
var
new BitmapImage
await
FileAccessMode
Metro style app
Language Support
(CLR, WinJS, CRT)
Language Projection
Windows
Metadata &
Namespace
UI
Pickers
Controls
Media
XAML
Storage
Network
…
Windows Runtime Core
Windows Core
Web Host (HTML,
CSS, JavaScript))
Runtime Broker
Your Managed
Code
Windows
Runtime
Windows 8 API
You already have the skills to build
Metro style apps with C# and VB
• The relationship between .NET and the Windows Runtime
• Using Windows Runtime APIs from C# and Visual Basic
• Building Window Runtime Components in C# and Visual Basic
C# and Visual Basic influenced
the Windows Runtime
Using the Windows Runtime
feels natural and familiar
from C# and Visual Basic
var
new CameraCaptureUI
new Size
var
await
CameraCaptureUIMode
if
var
new BitmapImage
await
FileAccessMode
var
DataTransferManager.GetForCurrentView
new TypedEventHandler<DataTransferManager
DataRequestedEventArgs
void
if
null
"No Image Taken"
else
try
{
var
new CameraCaptureUI
new Size
catch (Exception e)
{
//Exception handling code
}
ComException
var picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
var files = await picker.PickMultipleFilesAsync();
foreach (var file in files)
{
lbFiles.Items.Add(file.FileName);
}
PickMultipleFilesOperation PickMultipleFilesAsync();
public sealed class PickMultipleFilesOperation :
IAsyncOperation<IReadOnlyList<StorageFile>>, IAsyncInfo
var picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
var files = await picker.PickMultipleFilesAsync();
foreach (StorageFile file in files)
{
lbFiles.Items.Add(file.FileName);
}
System.Collections.Generic.IReadOnlyList
<Windows.Storage.StorageFile>
var picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
var files = await picker.PickMultipleFilesAsync();
foreach (StorageFile file in files)
{
lbFiles.Items.Add(file.FileName);
}
System.Collections.Generic.IReadOnlyList
Windows.Foundation.Collections.IVectorView
<Windows.Storage.StorageFile>
<Windows.Storage.StorageFile>
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
StorageFile file = await picker.PickSingleFileAsync();
Windows.Storage.Streams.IInputStream inputStream =
await file.OpenForReadAsync();
System.IO.Stream stream = inputStream.AsStream();
System.IO.StreamReader reader = new StreamReader(stream);
string contents = reader.ReadToEnd();
internal async void ProtectBytes(byte[] data, BinaryWriter output)
{
DataProtectionProvider dpp = new DataProtectionProvider();
IBuffer result = await dpp.ProtectAsync(data.AsBuffer());
byte[] protectedData;
int start = 0;
if (result.TryGetUnderlyingData(out protectedData, out start))
output.Write(protectedData);
else
throw new InvalidOperationException();
}
You can write your own
Windows Runtime components
in C# or Visual Basic
You should build a Windows Runtime component
when you want your code to be used from
JS, C++, C# and VB
ComVisible(true), Guid("06D7901C-9045-4241-B8A0-39A1AC0F8618")]
public interface IWindowsApiSample
{
string HelloWorld();
}
[ComVisible(true), [ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IWindowsApiSample))]
public class WindowsApiSample : IWindowsApiSample
{
public string HelloWorld() {
return "Hello, World!";
}
}
public sealed class MyClassLibrary
{
public string HelloWorld()
{
return "Hello, World!";
}
}
By adhering to a few simple rules, you can build
a managed Windows Runtime component
that projects into C++ or JavaScript
Only the public types and members
in your managed Windows Runtime component
project need to follow the simple rules
public sealed class ManagedLibrary
{
public List<int> GetNumbers()
{
List<int> numbers = new List<int>();
numbers.AddRange(new int[] {0,1,1,2,3});
return numbers;
}
}
public sealed class ManagedLibrary
{
public IList<int> GetNumbers()
{
List<int> numbers = new List<int>();
numbers.AddRange(new int[] {0,1,1,2,3});
return numbers;
}
}
private async Task<string> GetTweetTaskAsync()
{
string url = "http://api.twitter.com/1/statuses/" +
"user_timeline.xml?screen_name=bldwin";
var http = new HttpClient();
var resp = await http.GetAsync(url);
var xml = XDocument.Load(resp.Content.ContentReadStream);
var str = xml.Descendants("text")
.Select(x => x.Value).First();
return str;
}
public IAsyncOperation<string> GetTweetAsync()
{
return AsyncInfoFactory.Create(
() => this.GetTweetTaskAsync());
}
Visual Studio has built-in support for managed
Windows Runtime component projects
You already have the skills to build
Metro style apps with C# and VB
Influenced by C# and VB
Feels natural and familiar from
C# and Visual Basic
Build your own managed
Windows Runtime components
Related sessions
•
•
•
•
•
•
•
•
PLAT-874T: Lap around the Windows
Runtime
TOOL-930C: A .NET developer's view of
Windows 8 app development
TOOL-810T: Async made simple in
Windows 8, with C# and Visual Basic
APP-737T: Metro style apps using XAML:
what you need to know
TOOL-532T: Using the Windows Runtime
from C++
TOOL-533T: Using the Windows Runtime
from JavaScript
PLAT-875T: Windows Runtime internals:
understanding "Hello World"
PLAT-876T: Lessons learned designing the
Windows Runtime
Documentation & articles
•
•
•
Tour of the IDE for C#, C++ and Visual
Basic Developers
Building your first Windows Metro style app
with C++, C# or Visual Basic
Roadmap for creating Metro style apps in
C#, C++ and Visual Basic
Contact
•
•
•
•
Please visit the forums on the Windows Dev
Center at http://forums.dev.windows.com
We’ll be active on the Building Metro style
Apps with C# or VB forum
For best response, please include the Session
ID in the title of your post
This talk’s Session ID is TOOL-531T
http://forums.dev.windows.com
http://bldw.in/SessionFeedback