Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native code in C#?

I was watching the Microsoft build conference from October last year and I noticed they announced that for building the new Metro style apps, developers can write native code in C#. How is this possible? I'm just curious. Wasn't C# designed (as part of CLI standards) to first be compiled to intermediate byte code and then run on a virtual machine? How can something that runs on a virtual machine be called "native code"?

like image 832
Ayush Avatar asked Oct 22 '22 18:10

Ayush


1 Answers

It has always been possible to call native code from managed code. Generally any .net app that interacts with windows at some point is handing control over to native components.

Historically, to manually invoke native code we would use PInvoke (Platform Invocation) - which allows managed code to call unmanaged functions that are implemented in a DLL.

What's new now is Windows Runtime, basically an ehanced COM-based API. You can read up about it here - http://en.wikipedia.org/wiki/Windows_Runtime - its just making the process easier / less overheard.

EDIT - to be clear, the presentation was not that c# could be compiled to native code. this is still not possible. they were touting winrt as providing a new (cleaner) mechanism for including calls to native code in c#.

like image 98
bkr Avatar answered Nov 17 '22 12:11

bkr