Latest Entries »

Windows Runtime (WinRT) is the principal provider of system services for applications in Windows 8 that will be designed to incorporate the new “Metro” style. It is Microsoft’s new programming model that supports development in C++, C#, VB.NET as well as JavaScript. WinRT components are designed with an eye to interoperability between multiple languages and APIs, including native (C++), managed (C#) and scripting (JavaScript).

WinRT is not a replacement for any part of Windows we have come to know. Desktop applications written in earlier versions of Windows, will run properly in the desktop mode on Windows 8.

The following picture shows an overview of the traditional desktop applications and the new metro style applications. We also see the APIs that supports the programming languages in the new platform.

Through the above APIs, the developer can communicate with other APIs on the basis of numerous objects. There are more than 800 objects available for approaching APIs. Every object implements several interfaces. These interfaces are located in the registry.

These are the API’s of Windows Runtime:

Every WinRT object supports interfaces, and two of these interfaces are very important: IUknown and IInspectable. The first one is a sort of a parent interface where every other interface inherit from it, directly or indirectly. IIspectable is an interface to inspect an object and to know what the members are. If you want to create an object in WinRT, for example, to communicate with the webcam, you call a certain class. This class looks then in the Activation Store, which is located in the registry, to implement the necessary interfaces. Once the interfaces are implemented, this information is stored in the Windows metadata.

Below there is an example of the FileInformation class which has 3 interfaces. As a developer you will not see these interfaces, but they will be implemented as soon as you use the FileInformation class. What exactly happens here is that the FileInformation class will obtain the interfaces from the Activation Store. The object is then activated from the Registry, and stored in the Windows metadata.

So once we have created an object, we can communicate and interact with it. On the left of the image below, we have our object, and at the right of it there are  our applications written in C + +, C # and JavaScript. Now the question is: when will our applications communicate with the object to use its services?

If it’s a C + + application, the compiler goes at compile time to the metadata and takes all the information it needs out of it, and puts it in the executable at runtime so you no longer need to look at the metadata. So it then can communicate directly with the object. In C # and VB, it is a combination of both at compile time and at runtime exploring the metadata and taking the information necessary to communicate with the object. The same happens with JavaScript, only the metadata is generated dynamically at runtime, which is actually intended for dynamic programming languages such as JavaScript.

 

This was a short introduction about Microsoft’s new platform Windows Runtime and a description of what happens when you create an object in it’s environment.

The images used in this article come from Microsoft’s Build event.

Delegates in C#

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value.

Any method that matches the delegate’s signature, which consists of the return type and parameters, can be assigned to the delegate. This makes it possible to programmatically change method calls, and also plug new code into existing classes. As long as you know the delegate’s signature, you can assign your own delegated method.

The first step is defining the delegate:

public delegate int Calculate (int value1, int value2);

Second, we create a method which will be assigned to the delegate object:

public int add(int value1, int value2){
 return value1 + value2;
}

Now, we create the delegate object and assigning the method to it:

MyClass mc = new MyClass();

Calculate add = new Calculate(mc.add);

Finally, we call the method via the delegate object:

Console.WriteLine("Adding two values: " + add(10, 6));
Follow

Get every new post delivered to your Inbox.