<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marius Bancila's Blog &#187; Windows Programming</title>
	<atom:link href="http://mariusbancila.ro/blog/category/it/software/windows-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://mariusbancila.ro/blog</link>
	<description>Sharing my opinions and ideas!</description>
	<lastBuildDate>Mon, 14 Nov 2011 07:19:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Things I like about native development with C++/CX</title>
		<link>http://mariusbancila.ro/blog/2011/11/12/things-i-like-about-native-development-with-ccx/</link>
		<comments>http://mariusbancila.ro/blog/2011/11/12/things-i-like-about-native-development-with-ccx/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 22:06:21 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[CTPs & Betas]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[partial classes]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[VisualStudio]]></category>
		<category><![CDATA[VS10]]></category>
		<category><![CDATA[VS11]]></category>
		<category><![CDATA[VS2010]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=1182</guid>
		<description><![CDATA[Visual Studio 11 brings many new things for native development, including support for new features from C++11 (unfortunately not all), or ability to write Metro apps with C++/CX including modeling the UI with XAML. In this post I will talk a bit about three favorite features that I noticed immediately after trying VS11 from Windows [...]]]></description>
			<content:encoded><![CDATA[<p>Visual Studio 11 brings many new things for native development, including support for new features from C++11 (unfortunately not all), or ability to write Metro apps with C++/CX including modeling the UI with XAML. In this post I will talk a bit about three favorite features that I noticed immediately after trying VS11 from Windows 8 Developer Preview.</p>
<p><strong>Use of namespaces</strong><br />
Finally, I see namespaces promoted in native code. Yes, it&#8217;s C++/CX and they were probably forced to use namespaces for a consistent experience from the various languages that target the Windows Runtime, but it&#8217;s a very nice change to the default templates for C++ projects where everything is put in the global namespace. I can only hope they will improve that in this version or the next for standard C++ applications (whether Win32 console apps or MFC apps).</p>
<pre class="cpp" name="code">
namespace Sample
{
    public ref class MainPage
    {
        public:
            MainPage();
            ~MainPage();
    };
}
</pre>
<p><strong>UPDATE</strong>: looks like I wasn&#8217;t clear enough, I&#8217;m not saying namespaces is a new C++ feature (duh), I&#8217;m saying Visual Studio templates for C++ don&#8217;t promote that. Create a Win32 project, an MFC project, and ATL project, there are no namespaces. You&#8217;d have to code everything manually, but if you do it, you mess the wizards. So, what I&#8217;m saying is that I hope we can see namespaces <u>promoted</u> for other project and item templates too.</p>
<p><strong>Partial classes</strong><br />
I <a href="http://mariusbancila.ro/blog/2011/10/13/cpp-winrt-and-partial-classes/">already wrote about partial classes</a>, but I want to reiterate this feature. Partial classes gives you the ability to define a class in several files. This is great because developers and code generator tools such as designers can edit different parts of the same class without interfering one with the other. This feature made it possible for supporting XAML user interfaces in C++/CX Metro applications.</p>
<p>I&#8217;m actually wondering why isn&#8217;t this already part of standard C++ and I can only wish that the next version (which hopefully will not take another decade to conclude) will include this feature.</p>
<p><strong>Better Syntax Highlighting</strong><br />
Below is a comparison for the same piece of code highlighted by Visual Studio 2010 on the left, and Visual Studio.vNext (11) on the right.<br />
<a href="/blog/wp-content/uploads/2011/11/vs10syntaxhighlight.png"><img alt="" src="/blog/wp-content/uploads/2011/11/vs10syntaxhighlight.png" title="Highlighting with VS10" class="alignnone" width="400" /></a><a href="/blog/wp-content/uploads/2011/11/vs11syntaxhighlight.png"><img alt="" src="/blog/wp-content/uploads/2011/11/vs11syntaxhighlight.png" title="Highlighting with VS11" class="alignnone" width="400" /></a><br />
There is hardly any formatting in VS10. However, on the other hand, the highlighting in VS11 is beautiful. User defined types (including library types) are displayed with another color than the built-in types (such as int), including in their definition. STL types (string, vector, etc.) are finally identified as types and displayed with the appropriate color. Also the name of parameters is displayed in italics which makes them easily identifiable. There are other things about the highlighting, but these striking changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2011/11/12/things-i-like-about-native-development-with-ccx/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>WinRT and winmd Files</title>
		<link>http://mariusbancila.ro/blog/2011/10/30/winrt-and-winmd-files/</link>
		<comments>http://mariusbancila.ro/blog/2011/10/30/winrt-and-winmd-files/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 19:15:40 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[CTPs & Betas]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[C++/CX]]></category>
		<category><![CDATA[ildasm]]></category>
		<category><![CDATA[managed]]></category>
		<category><![CDATA[native]]></category>
		<category><![CDATA[win8]]></category>
		<category><![CDATA[winmd]]></category>
		<category><![CDATA[winrt]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=1162</guid>
		<description><![CDATA[If you tried the Win8 Developer Preview and built WinRT components (native or managed) you noticed the .winmd files. The name stands for Windows Meta Data and the format of these files is the same used by the .NET framework for the CLI, i.e. ECMA-335. That means you can actually read these files with a [...]]]></description>
			<content:encoded><![CDATA[<p>If you tried the Win8 Developer Preview and built WinRT components (native or managed) you noticed the <strong>.winmd</strong> files. The name stands for Windows Meta Data and the format of these files is the same used by the .NET framework for the CLI, i.e. <a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm">ECMA-335</a>. That means you can actually read these files with a tool such as ILDASM or Reflector, or of course, through .NET Reflection.</p>
<p>If you look in C:\Windows\System32\WinMetadata folder you&#8217;ll find the WinMD files for the Windows Runtime. You can browse the content of these files with one of the aforementioned disassemblers.<br />
<img alt="" src="/blog/wp-content/uploads/2011/10/winmetadatafolder.png" title="WinMetadata folder" class="alignnone" width="856" height="601" /></p>
<p>Here are two dummy WinRT components, one developed in C++/CX and one in C#.</p>
<table>
<tr>
<td>Native WinRT component in C++/CX</td>
<td>Managed WinRT component in C#</td>
</tr>
<tr valign="top">
<td>
<pre class="cpp" name="code">
namespace WinRTNativeComponent
{
    public ref class MyWinRTComponent sealed
    {
        int _id;
		String^ _name;

    public:
		MyWinRTComponent () {}
		~MyWinRTComponent () {}

        property int Id
        {
            int get() { return _id; }
            void set(int value) { _id = value; }
        }

		property String^ Name
		{
			String^ get() {return _name;}
			void set(String^ value) { _name= value; }
		}

        bool Update(int id, String^ name)
		{
			{
				if(_id == id)
				{
					_name = name;
					return true;
				}

				return false;
			}
		}
    };
}
</pre>
</td>
<td>
<pre class="csharp" name="code">
namespace WinRTManagedComponent
{
    public sealed class MyWinRTComponent
    {
        public int Id { get; set; }
        public string Name { get; set; }

        bool Update(int id, string name)
        {
            if (Id == id)
            {
                Name = name;
                return true;
            }

            return false;
        }
    }
}
</pre>
</td>
</tr>
</table>
<p>In the case of the native component, the output includes a DLL and a WINMD file (and of course a PDB file). In the case of the managed component, the output is either a DLL only or a WINMD only (plus the associated PDB file), depending on the Output type as defined in the project properties. If the type is <strong>Class Library</strong> the output is a DLL; this is enough if your component is supposed to be consumed from a managed language. However, if the component should be consumed from C++/CX or Javascript, then the project type must be set to <strong>WinMD File</strong>. In this case the DLL is replaced by a WinMD file, that contains, at least in the current version, both the matadata (as implied by the name) and the implementation.</p>
<table>
<tr>
<td>Native WinRT component in C++/CX</td>
<td>Managed WinRT component in C#</td>
</tr>
<tr valign="top">
<td><img alt="" src="/blog/wp-content/uploads/2011/10/winmdnative.png" title="WinMD for native component" class="alignnone" width="419" height="600" /></td>
<td><img alt="" src="/blog/wp-content/uploads/2011/10/winmdmanaged.png" title="WinMD for managed component" class="alignnone" width="419" height="600" /></td>
</tr>
</table>
<p>It should be possible to use reflection with winmd files. However, the reflection capabilities of .NET 4.5 in this developer preview seem to be very limited. The only available Load method in the Assembly class is</p>
<pre class="csharp" name="code">
public static Assembly Load(AssemblyName assemblyRef);
</pre>
<p>Trying to load the winmd file fails with a FailLoadException with the message &#8220;Could not load file or assembly &#8216;Winmdreflection, ContentType=WindowsRuntime&#8217; or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0&#215;80131515)&#8221;.</p>
<pre class="csharp" name="code">
try
{
    var assembly = Assembly.Load(
        new AssemblyName()
        {
            Name = "WinRTManagedComponent",
            ContentType = AssemblyContentType.WindowsRuntime
        });
}
catch (Exception ex)
{
}
</pre>
<p>It is possible though to read information for the types described in an winmd file in native code using the  <a href="http://msdn.microsoft.com/en-us/library/ms230172.aspx">IMetaDataImport</a>/<a href="http://msdn.microsoft.com/en-us/library/ms232953.aspx">IMetaDataImport2</a> COM interfaces. You can find an example <a href="http://social.msdn.microsoft.com/Forums/en-AU/winappswithnativecode/thread/211ef583-db11-4e55-926b-6d9ab53dbdb4">here</a>. But this has the drawback that you have to instantiate an object first and then query for its type information.</p>
<p>To use a Windows Runtime component in a Metro application (managed or native) you have to add a reference to it. That is pretty straight forward. In the following example I&#8217;m adding a reference in a C++ Metro application to the two WinRT components, one native and one managed, shown earlier. To do this, you can go to the project&#8217;s property page and open the Common Properties > Frameworks and References page, or use the References command from the project&#8217;s context menu which opens that page directly. You can add a reference to a project from the same solution, to a Windows component or you can browse for the winmd file.<br />
<img alt="" src="/blog/wp-content/uploads/2011/10/winmdreference.png" title="Adding a references to an winmd file" class="alignnone" width="800" height="556" /></p>
<p>Having done that you can instantiate the WinRT components.</p>
<pre class="cpp" name="code">
auto obj1 = ref new WinRTManagedComponent::MyWinRTComponent();
obj1->Id = 1;
obj1->Name = L"marius";

auto obj2 = ref new WinRTNativeComponent::MyWinRTComponent();
obj2->Id = 1;
obj2->Name = L"marius";
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2011/10/30/winrt-and-winmd-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C++, WinRT and Partial Classes</title>
		<link>http://mariusbancila.ro/blog/2011/10/13/cpp-winrt-and-partial-classes/</link>
		<comments>http://mariusbancila.ro/blog/2011/10/13/cpp-winrt-and-partial-classes/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 20:46:05 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[XAML]]></category>
		<category><![CDATA[C++/CX]]></category>
		<category><![CDATA[partial classes]]></category>
		<category><![CDATA[VisualStudio]]></category>
		<category><![CDATA[VS11]]></category>
		<category><![CDATA[winrt]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=1131</guid>
		<description><![CDATA[Partial classes are finally available to C++. Sort of. It&#8217;s not part of the new C++11 standard, it&#8217;s part of the C++/CX language developed by Microsoft for targeting WinRT on Windows 8. Partial classes mean that you can define a class spanned across several files. Why is this great? Because it allows developers and automatic [...]]]></description>
			<content:encoded><![CDATA[<p>Partial classes are finally available to C++. Sort of. It&#8217;s not part of the new C++11 standard, it&#8217;s part of the C++/CX language developed by Microsoft for targeting WinRT on Windows 8.</p>
<p>Partial classes mean that you can define a class spanned across several files. Why is this great? Because it allows developers and automatic code generator tools (such as designers) to edit parts of the same class without interfering one with another. WinRT allows C++ developers to write UI in XAML. This could not have been possible without the support for partial classes. </p>
<p>Partial classes:</p>
<ul>
<li>are available only for ref classes; native classes are not supported</li>
<li>are introduced with the <strong>partial</strong> keyword in all definitions but one</li>
</ul>
<p>Here is an example:</p>
<pre class="cpp" name="code">
// foo.private.h
#pragma once

partial ref class foo // <- here the partial keyword is used
{
private:
   int _id;
   Platform::String^ _name;
};
</pre>
<pre class="cpp" name="code">
// foo.public.h
#pragma once
#include "foo.private.h"

ref class foo // <- partial keyword is not used here
{
public:
   int GetId();
   Platform::String^ GetName();
};
</pre>
<pre class="cpp" name="code">
// foo.cpp
#include "pch.h"
#include "foo.public.h"

int foo::GetId() {return _id;}
Platform::String^ foo::GetName {return _name;}
</pre>
<p>What happens when you add a new page to a C++ Metro style application? The wizard generates three files: a XAML file and a header and cpp file as the code behind. Let's say the page is called MainPage. In this case the three files are MainPage.xaml (code below is a dummy example), MainPage.xaml.h and MainPage.xaml.cpp.</p>
<pre class="cpp" name="code">
&lt;UserControl x:Class="DemoApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="768" d:DesignWidth="1366"&gt;

    &lt;StackPanel Name="firstPanel"&gt;
        &lt;Button Name="firstButon" /&gt;
    &lt;/StackPanel&gt;

&lt;/UserControl&gt;
</pre>
<pre class="cpp" name="code">
//
// MainPage.xaml.h
// Declaration of the MainPage.xaml class.
//

#pragma once

#include "pch.h"
#include "MainPage.g.h"

namespace DemoApp
{
   public ref class MainPage
   {
      public:
         MainPage();
         ~MainPage();
   };
}
</pre>
<pre class="cpp" name="code">
//
// MainPage.xaml.cpp
// Implementation of the MainPage.xaml class.
//

#include "pch.h"
#include "MainPage.xaml.h"

using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Data;
using namespace DemoApp;

MainPage::MainPage()
{
   InitializeComponent();
}

MainPage::~MainPage()
{
}
</pre>
<p>You can notice that the objects <em>firstPanel</em> and <em>firstButton</em> are not defined in the header for MainPage and second, MainPage.xaml.h includes MainPage.g.h. So what is this? This is a designer generated file, which together with MainPage.g.cpp completes the definition of the MainPage ref class. These files are not generated until you start a build. After you do that you can find them in the output folder (Debug or Release for instance). This is how they look:</p>
<pre class="cpp" name="code">
#pragma once
//------------------------------------------------------------------------------
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
//------------------------------------------------------------------------------

namespace Windows {
    namespace UI {
        namespace Xaml {
            namespace Controls {
                ref class StackPanel;
                ref class Button;
            }
        }
    }
}

namespace DemoApp
{
    partial ref class MainPage : public Windows::UI::Xaml::Controls::UserControl,
                                                     public Windows::UI::Xaml::Markup::IComponentConnector
    {
    public:
        void InitializeComponent();
        void Connect(int connectionId, Platform::Object^ pTarget);

    private:
        Windows::UI::Xaml::Controls::StackPanel^ firstPanel;
        Windows::UI::Xaml::Controls::Button^ firstButon;
    };
}
</pre>
<pre class="cpp" name="code">
//------------------------------------------------------------------------------
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
//------------------------------------------------------------------------------
#include "pch.h"

#include "MainPage.xaml.h"

using namespace Windows::Foundation;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Markup;
using namespace MyDemoApplication1;

void MainPage::InitializeComponent()
{
    // Call LoadComponent on ms-resource://DemoApp/Files/MainPage.xaml
    Windows::UI::Xaml::Application::LoadComponent(this, ref new Windows::Foundation::Uri("ms-resource://DemoApp/Files/MainPage.xaml"));

    // Get the StackPanel named 'firstPanel'
    firstPanel = safe_cast&lt;Windows::UI::Xaml::Controls::StackPanel^&gt;(static_cast&lt;IFrameworkElement^&gt;(this)->FindName("firstPanel"));

    // Get the Button named 'firstButon'
    firstButon = safe_cast&lt;Windows::UI::Xaml::Controls::Button^&gt;(static_cast&lt;IFrameworkElement^&gt;(this)->FindName("firstButon"));

}

void MainPage::Connect(int connectionId, Platform::Object^ pTarget)
{
}
</pre>
<p>The following image illustrates the grouping of these files:<br />
<img alt="" src="/blog/wp-content/uploads/2011/10/cpppartialclass.png" title="C++/CX partial classes" class="alignnone" width="771" height="410" /><br />
MainPage.xaml is a XAML files, which can be edited both by the designer or manually by the developer (basically with the designer is still the developer that models the UI). The other files are C++/CX files. MainPage.xaml.h and MainPage.xaml.cpp are the files the developer writes, while MainPage.g.h and MainPage.g.cpp are edited by the designer. Do not modify the code in these files, because you could either mess up the designer, or all your changes would get lost when the file is regenerated.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2011/10/13/cpp-winrt-and-partial-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Windows Runtime</title>
		<link>http://mariusbancila.ro/blog/2011/09/15/windows-runtime/</link>
		<comments>http://mariusbancila.ro/blog/2011/09/15/windows-runtime/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 20:54:16 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[64bit]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[CTPs & Betas]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[WinRT]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[metro]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[runtime]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[winrt]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=1116</guid>
		<description><![CDATA[Windows Runtime, or shortly WinRT, is a new runtime (siting on top of the Windows kernel) that allows developers to write Metro style applications for Windows 8, using a variety of languages including C/C++, C#, VB.NET or JavaScript/HTML5. Microsoft has started rolling out information about Windows 8 and the new runtime at BUILD. WinRT is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211377%28v=VS.85%29.aspx">Windows Runtime</a>, or shortly WinRT, is a new runtime (siting on top of the Windows kernel) that allows developers to write Metro style applications for Windows 8, using a variety of languages including C/C++, C#, VB.NET or JavaScript/HTML5. Microsoft has started rolling out information about Windows 8 and the new runtime at <a href="http://www.buildwindows.com/">BUILD</a>.</p>
<div class="wp-caption alignnone" style="width: 643px"><img alt="" src="http://i.zdnet.com/blogs/archslide.png" title="Windows 8" width="633" height="427" /><p class="wp-caption-text">(source www.zdnet.com)</p></div>
<p>WinRT is a native layer (written in C++ and being COM-based) that is intended as a replacement, or alternative, to Win32, and enables development of &#8220;immersive&#8221; applications, using the Metro style. Its API is object oriented and can be consumed both from native or managed languages, as well as JavaScript. At the same time the old Win32 applications will continue to run just as before and you can still (and most certainly will) develop Win32 applications.</p>
<p>Microsoft has created a new language called C++ Component Extension, or simply C++/CX. While the syntax is very similar to C++/CLI, the language is not managed, it&#8217;s still native. WinRT components built in C++/CX do not compile to managed code, but to 100% native code. A good news for C++ developers is that they can use XAML now to build the UI for immersive applications. However, this is not available for classical, Win32 applications.</p>
<p>You can get a glimpse of the new system and the tools by downloading and installing the <a href="http://msdn.microsoft.com/en-us/windows/apps/br229516">Windows Developer Preview with tools</a>, that includes the following:</p>
<ul>
<li>64-bit Windows Developer Preview</li>
<li>Windows SDK for Metro style apps</li>
<li>Microsoft Visual Studio 11 Express for Windows Developer Preview</li>
<li>Microsoft Expression Blend 5 Developer Preview</li>
<li>28 Metro style apps including the BUILD Conference app</li>
</ul>
<p>Notice this is a pre-beta release and you might encounter various problems.</p>
<p>Before you start here are several additional articles that you might want to read:</p>
<ul>
<li><a href="http://www.infoq.com/news/2011/09/WinRT-API">WinRT: An Object Orientated Replacement for Win32</a></li>
<li><a href="http://www.infoq.com/news/2011/09/C-Component-Extensions">C++ Component Extensions: The New Face of COM</a></li>
<li><a href="http://www.infoq.com/news/2011/09/DotNet-On-WinRT">C# and Visual Basic on the WinRT API</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh441569%28v=VS.85%29.aspx">Creating Windows Runtime Components in C++</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh441589%28v=VS.85%29.aspx">Tutorial: Creating and using extension SDKs</a></li>
<li><a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-532T">Using the Windows Runtime from C++</a></li>
</ul>
<p>There are also several <a href="http://social.msdn.microsoft.com/Forums/en-US/category/windowsapps">new forums</a> available on MSDN forums for developing Metro style applications, which you can use for addressing technical questions. Hopefully thee will be answers from Microsoft people working in this area.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2011/09/15/windows-runtime/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C++ Renaissance at Microsoft</title>
		<link>http://mariusbancila.ro/blog/2011/06/20/cpp-renaissance-at-microsoft/</link>
		<comments>http://mariusbancila.ro/blog/2011/06/20/cpp-renaissance-at-microsoft/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 08:59:27 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Parallel Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[renaissance]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[VisualStudio]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=1019</guid>
		<description><![CDATA[At the beginning of this year, Microsoft announced a &#8220;C++ renaissance&#8221;. Quoting from the description of a Channel 9 video with Craig Symonds and Mohsen Agsen: C++ is currently undergoing a renaissance. This means that, by definition, the language, compilers and compositional tooling are evolving and coalescing into a state that maximizes native developer efficiency, [...]]]></description>
			<content:encoded><![CDATA[<p>At the beginning of this year, Microsoft announced a &#8220;C++ renaissance&#8221;. Quoting from the description of a <a href="http://channel9.msdn.com/">Channel 9</a> video with Craig Symonds and Mohsen Agsen:</p>
<blockquote><p>C++ is currently undergoing a renaissance. This means that, by definition, the language, compilers and compositional tooling are evolving and coalescing into a state that maximizes native developer efficiency, productivity, and creativity across hardware and software domains.</p></blockquote>
<p>Everybody agrees that Microsoft made C++ a sort of second class citizen in the past years, while the company invested a lot in the .NET framework. Many developers have switched from native development to managed (.NET) simply because it offers a more productive environment. And the postponing of the ISO standard committee in releasing the new C++0x standard only made things worse. </p>
<p>However, with the completion of the new C++ standard this year, Microsoft, apparently, plans to change that, and make C++ again appealing to developers. They already made C++0x features available in the VS2010 C++ compiler and are working on implementing most of the rest for Visual Studio vNext. They are also investing in tools (now labeled Application Lifecycle Management), and for instance are bringing intellisence to C++/CLI. One of the most important areas of development is parallelism, where they are developing the PPL and Agents libraries and now the C++ AMP that they just announced. And also recently the Kinect for Windows SDK beta that provides Kinect capabilities to developers who build applications with C++ (and other laguanges). And in the mean time <a href="http://blogs.msdn.com/b/jasonz/archive/2011/06/06/welcome-erich-gamma-to-the-visual-studio-team.aspx">they hired Erich Gamma in the Visual Studio team</a>.</p>
<p>But this is not enough in my opinion. Improvements in language and tools are an important part, but not everything. It is equally necessary for Microsoft to evangelize it, using any necessary means. Unless they can spread the word, the work might pass unnoticed. To be honest, I was very reluctant about this part, half an year ago, when they announced the &#8220;renaissance&#8221;. However, looking back at what they done I&#8217;d say they are on the right track. Of course, there is still a lot of work to match the &#8220;advertising&#8221; effort put into .NET. But right now C++ is getting more attention at conferences such as PDC or TechEd, or their publishing assets, such as Channel 9, MSDN or their team blogs. So I tried to assemble a collection of videos, blogs, books and code samples related to C++ or native development that they published since the announcement of the renaissance. So far it looks good, in my opinion.</p>
<p>Channel 9<br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/E2E-Herb-Sutter-and-Erik-Meijer-Perspectives-on-C">E2E: Herb Sutter and Erik Meijer &#8211; Perspectives on C++</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/Craig-Symonds-and-Mohsen-Agsen-C-Renaissance">Craig Symonds and Mohsen Agsen: C++ Renaissance</a><br />
<a href="http://channel9.msdn.com/posts/Windows-7-Taskbar-Integration-for-MFC-Applications">Windows 7 Taskbar Integration for MFC Applications</a><br />
<a href="http://channel9.msdn.com/Blogs/Charles/Tony-Goodhew-VC-Developer-Communication-Questions-and-Answers">Tony Goodhew: VC++ Developer Communication &#8211; Questions and Answers</a><br />
<a href="http://channel9.msdn.com/Blogs/Charles/VC-MVP-Summit-Kate-Gregory">Talkin&#8217; C++ with Kate Gregory</a><br />
<a href="http://channel9.msdn.com/Blogs/Charles/MVP-Summit-2011-Meet-C-MVPs-Angel-PJ-Tom-and-Sheng">MVP Summit 2011: Meet C++ MVPs Angel, PJ, Tom and Sheng</a><br />
<a href="http://channel9.msdn.com/Blogs/Charles/MVP-Summit-2011-Meet-C-MVPs-Alon-Marius-Bruno-and-Jim">Talkin&#8217; C++ with Alon, Marius, Bruno, and Jim</a><br />
<a href="http://channel9.msdn.com/posts/Talkin-C-with-Boris-Jabes-C-Intellisense-Game-Development-and-Boris-Faces-His-Demons">Talkin&#8217; C++ with Boris Jabes: C++ Intellisense, Game Development, and Boris Faces His Demons</a><br />
<a href="http://channel9.msdn.com/posts/Application-Restart-and-Recovery-on-Windows-7-in-Native-Code">Application Restart and Recovery on Windows 7 in Native Code</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/Parallel-Programming-in-Native-Code-Tasks-and-Continuations-Part-1-of-2">Parallel Programming for C++ Developers: Tasks and Continuations, Part 1 of 2</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/Parallel-Programming-for-C-Developers-Tasks-and-Continuations-Part-2-of-2">Parallel Programming for C++ Developers: Tasks and Continuations, Part 2 of 2</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/Conversation-with-Herb-Sutter-Perspectives-on-Modern-C0x11">Conversation with Herb Sutter: Perspectives on Modern C++(0x/11)</a><br />
<a href="http://channel9.msdn.com/posts/C-ALM--Architecture-Tools-and-Unit-Testing-for-Visual-C-Developers">First Look: New ALM Tools for VC++ Developers</a><br />
<a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DEV303">Modern Native C++ Development for Maximum Productivity</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/Mohsen-Agsen-C-Today-and-Tomorrow">Mohsen Agsen &#8211; C++ Today and Tomorrow</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answers">Herb Sutter: C++ Questions and Answers</a><br />
<a href="http://channel9.msdn.com/posts/AFDS-Keynote-Herb-Sutter-Heterogeneous-Computing-and-C-AMP">Herb Sutter &#8211; Heterogeneous Computing and C++ AMP</a><br />
<a href="http://channel9.msdn.com/posts/Daniel-Moth-Blazing-fast-code-using-GPUs-and-more-with-C-AMP">Daniel Moth: Blazing-fast code using GPUs and more, with C++ AMP</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-1-of-n">C9 Lectures: Stephan T Lavavej &#8211; Advanced STL, 1 of n</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-2-of-n">C9 Lectures: Stephan T Lavavej &#8211; Advanced STL, 2 of n</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-3-of-n">C9 Lectures: Stephan T Lavavej &#8211; Advanced STL, 3 of n</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-4-of-n">C9 Lectures: Stephan T Lavavej &#8211; Advanced STL, 4 of n</a><br />
<a href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-5-of-n">C9 Lectures: Stephan T Lavavej &#8211; Advanced STL, 5 of n</a></p>
<p>Visual C++ Team Blog<br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/01/05/damn-my-vc-project-is-building-slower-in-vs2010-what-do-i-do-now-a-step-by-step-guide.aspx">Grr&#8230; My VC++ Project Is Building Slower in VS2010. What Do I Do Now? (A Step by Step Guide)</a><br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/03/03/10136696.aspx">C++/CLI IntelliSense in Visual Studio vNext</a><br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/03/22/10143956.aspx">Exception Boundaries: Working With Multiple Error Handling Mechanisms</a><br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/03/29/10146895.aspx">Troubleshooting Tips for IntelliSense Slowness</a><br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/04/05/10149742.aspx">Build Related Improvement in VS2010 SP1</a><br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/05/04/10161066.aspx">Converting An MFC Ribbon To Designer Format</a><br />
<a href="http://blogs.msdn.com/b/vcblog/archive/2011/05/26/10168887.aspx">Enforcing Correct Concurrent Access of Class Data</a></p>
<p>Parallel Programming in Native Code Blog<br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/01/15/sorting-in-ppl.aspx">Sorting in PPL</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/01/26/how-to-pick-your-parallel-sort.aspx">How to pick your parallel sort?</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/02/21/the-concurrency-runtime-and-visual-c-2010-lambda-expressions.aspx">The Concurrency Runtime and Visual C++ 2010: Lambda Expressions</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/02/28/the-concurrency-runtime-and-visual-c-2010-automatic-type-deduction.aspx">The Concurrency Runtime and Visual C++ 2010: Automatic Type Deduction</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/03/07/the-concurrency-runtime-and-visual-c-2010-the-decltype-type-specifier.aspx">The Concurrency Runtime and Visual C++ 2010: The decltype Type Specifier</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/03/14/the-concurrency-runtime-and-visual-c-2010-rvalue-references.aspx">The Concurrency Runtime and Visual C++ 2010: Rvalue References</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/03/24/the-concurrency-runtime-and-visual-c-2010-transporting-exceptions-between-threads.aspx">The Concurrency Runtime and Visual C++ 2010: Transporting Exceptions between Threads</a><br />
<a href="http://blogs.msdn.com/b/nativeconcurrency/archive/2011/03/23/building-responsive-gui-applications-with-ppl-tasks.aspx">Building Responsive GUI Applications with PPL Tasks</a></p>
<p>MSDN Magazine<br />
<a href="http://msdn.microsoft.com/en-us/magazine/gg650659.aspx">Writing a Debugging Tools for Windows Extension</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/hh148143.aspx">Writing a Debugging Tools for Windows Extension, Part 2: Output</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/hh205613.aspx">Writing a Debugging Tools for Windows Extension, Part 3: Clients and Callbacks</a><br />
<a href="http://msdn.microsoft.com/en-us/magazine/hh205645.aspx">Agile C++ Development and Testing with Visual Studio and TFS</a></p>
<p>Books &#038; Publications<br />
<a href="http://parallelpatternscpp.codeplex.com/">Parallel Programming with Microsoft Visual C++</a><br />
<a href="http://paper.li/visualc/news">The Visual C++ Weekly</a></p>
<p>Code &#038; Samples<br />
<a href="http://archive.msdn.microsoft.com/concrtextras">Code samples for the Concurrency Runtime and Parallel Pattern Library in Visual Studio 2010</a><br />
<a href="http://code.msdn.microsoft.com/Bing-Maps-Trip-Optimizer-003021ae">Bing Maps Trip Optimizer</a><br />
<a href="http://msdn.microsoft.com/en-us/library/ff708696.aspx">Hilo: Developing C++ Applications for Windows 7</a><br />
<a href="http://1code.codeplex.com/">All-in-One Code Framework</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2011/06/20/cpp-renaissance-at-microsoft/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Finding Installed Applications with VC++</title>
		<link>http://mariusbancila.ro/blog/2011/05/01/finding-installed-applications-with-vc/</link>
		<comments>http://mariusbancila.ro/blog/2011/05/01/finding-installed-applications-with-vc/#comments</comments>
		<pubDate>Sun, 01 May 2011 21:32:43 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[MSI]]></category>
		<category><![CDATA[registry]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=909</guid>
		<description><![CDATA[Finding applications installed on a machine (the ones that you see in Control Panel Add/Remove programs) could be a little bit tricky, because there isn&#8217;t a bulletproof API or method. Each of the available methods has its own weak points. WMI is slow and can actually be disabled on a machine. MSI API only shows [...]]]></description>
			<content:encoded><![CDATA[<p>Finding applications installed on a machine (the ones that you see in Control Panel Add/Remove programs) could be a little bit tricky, because there isn&#8217;t a bulletproof API or method. Each of the available methods has its own weak points. WMI is slow and can actually be disabled on a machine. MSI API only shows applications installed with an MSI, and reading directly from the Windows Registry is not an officially supported alternative. Thus it is an open point which one is the most appropriate, though the official answer will probably be MSI API.</p>
<p>In this post I will go through all of these three methods and show how to query for the installed applications and display the name, publisher, vendor and installation location (if available). Notice these are just some samples, and if you want to use this in your applications you&#8217;ll probably want to do additional things like better error checking. Because I want the code to work both with ANSI and UNICODE I will use the following defines</p>
<pre name="code" class="cpp">
#include <iostream >
#include <string>

#ifdef _UNICODE
#define tcout       wcout
#define tstring     wstring
#else
#define tcout       cout
#define tstring     string
#endif
</pre>
<p><strong>WMI</strong><br />
<a href="http://msdn.microsoft.com/en-us/library/aa394378.aspx">Win32_Product</a> is a WMI class that represents a product installed by Windows Installer. For fetching the list of installed applications with WMI I will reuse the WMIQuery class I first shown in this <a href="http://mariusbancila.ro/blog/2011/01/05/finding-if-a-computer-is-a-laptop/">post</a>. You need to include <strong>Wbemidl.h</strong> and link with <strong>wbemuuid.lib</strong>. </p>
<p>In the code shown below WmiQueryValue() is a function that reads a property from the current record and returns it as an STL string (UNICODE or ANSI). WmiEnum() is a function that fetches and displays in the console all the installed applications.</p>
<pre name="code" class="cpp">
class WMIQuery
{
   IWbemLocator* m_pLocator;
   IWbemServices* m_pServices;

public:
   WMIQuery():
      m_pLocator(NULL),
      m_pServices(NULL)
   {
   }

   bool Initialize()
   {
      // Obtain the initial locator to WMI
      HRESULT hr = ::CoCreateInstance(
         CLSID_WbemLocator,
         0,
         CLSCTX_INPROC_SERVER,
         IID_IWbemLocator, (LPVOID *) &#038;m_pLocator);

      if (FAILED(hr))
      {
         cerr &lt;&lt; "Failed to create IWbemLocator object. Err code = 0x" &lt;&lt; hex &lt;&lt; hr &lt;&lt; endl;
         return false;
      }

      // Connect to WMI through the IWbemLocator::ConnectServer method
      // Connect to the root\cimv2 namespace with the current user
      hr = m_pLocator->ConnectServer(
         _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
         NULL,                    // User name. NULL = current user
         NULL,                    // User password. NULL = current
         0,                       // Locale. NULL indicates current
         NULL,                    // Security flags.
         0,                       // Authority (e.g. Kerberos)
         0,                       // Context object
         &#038;m_pServices             // pointer to IWbemServices proxy
         );

      if (FAILED(hr))
      {
         cerr &lt;&lt; "Could not connect. Error code = 0x" &lt;&lt; hex &lt;&lt; hr &lt;&lt; endl;
         m_pLocator->Release();
         m_pLocator = NULL;
         return false;
      }

      // Set security levels on the proxy
      hr = ::CoSetProxyBlanket(
         m_pServices,                 // Indicates the proxy to set
         RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
         RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
         NULL,                        // Server principal name
         RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx
         RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
         NULL,                        // client identity
         EOAC_NONE                    // proxy capabilities
         );

      if (FAILED(hr))
      {
         cerr &lt;&lt; "Could not set proxy blanket. Error code = 0x" &lt;&lt; hex &lt;&lt; hr &lt;&lt; endl;
         m_pServices->Release();
         m_pServices = NULL;
         m_pLocator->Release();
         m_pLocator = NULL;
         return false;
      }

      return true;
   }

   IEnumWbemClassObject* Query(LPCTSTR strquery)
   {
      IEnumWbemClassObject* pEnumerator = NULL;
      HRESULT hr = m_pServices->ExecQuery(
         bstr_t("WQL"),
         bstr_t(strquery),
         WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
         NULL,
         &#038;pEnumerator);

      if (FAILED(hr))
      {
         cerr &lt;&lt; "Query for operating system name failed. Error code = 0x" &lt;&lt; hex &lt;&lt; hr &lt; endl;
         return NULL;
      }

      return pEnumerator;
   }

   ~WMIQuery()
   {
      if(m_pServices != NULL)
      {
         m_pServices->Release();
         m_pServices = NULL;
      }

      if(m_pLocator != NULL)
      {
         m_pLocator->Release();
         m_pLocator = NULL;
      }
   }
};

tstring WmiQueryValue(IWbemClassObject* pclsObj,
                      LPCWSTR szName)
{
    tstring value;

    if(pclsObj != NULL &#038;&#038; szName != NULL)
    {
        VARIANT vtProp;

        HRESULT hr = pclsObj->Get(szName, 0, &#038;vtProp, 0, 0);
        if(SUCCEEDED(hr))
        {
            if(vtProp.vt == VT_BSTR &#038;&#038; ::SysStringLen(vtProp.bstrVal) > 0)
            {
#ifdef _UNICODE
                value = vtProp.bstrVal;
#else
                int len = ::SysStringLen(vtProp.bstrVal)+1;
                if(len > 0)
                {
                    value.resize(len);
                    ::WideCharToMultiByte(CP_ACP,
                                          0,
                                          vtProp.bstrVal,
                                          -1,
                                          &#038;value[0],
                                          len,
                                          NULL,
                                          NULL);
                }
#endif
            }
        }
    }

    return value;
}

void WmiEnum()
{
    HRESULT hres;

    // Initialize COM.
    hres =  ::CoInitializeEx(0, COINIT_MULTITHREADED);
    if (FAILED(hres))
    {
        cout &lt;&lt; "Failed to initialize COM library. Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl;
        return;
    }

    // Set general COM security levels
    hres =  ::CoInitializeSecurity(
        NULL,
        -1,                          // COM authentication
        NULL,                        // Authentication services
        NULL,                        // Reserved
        RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication
        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
        NULL,                        // Authentication info
        EOAC_NONE,                   // Additional capabilities
        NULL                         // Reserved
        );

    if (FAILED(hres))
    {
        cout &lt;&lt; "Failed to initialize security. Error code = 0x" &lt;&lt; hex &lt;&lt; hres &lt;&lt; endl;
        ::CoUninitialize();
        return;
    }
    else
    {
        WMIQuery query;
        if(query.Initialize())
        {
            IEnumWbemClassObject* pEnumerator = query.Query(_T("SELECT * FROM Win32_Product"));

            if(pEnumerator != NULL)
            {
                // Get the data from the query
                IWbemClassObject *pclsObj;
                ULONG uReturn = 0;

                while (pEnumerator)
                {
                    HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &#038;pclsObj, &#038;uReturn);

                    if(0 == uReturn)
                    {
                        break;
                    }

                    // find the values of the properties we are interested in
                    tstring name = WmiQueryValue(pclsObj, L"Name");
                    tstring publisher = WmiQueryValue(pclsObj, L"Vendor");
                    tstring version = WmiQueryValue(pclsObj, L"Version");
                    tstring location = WmiQueryValue(pclsObj, L"InstallLocation");

                    if(!name.empty())
                    {
                        tcout &lt;&lt; name &lt;&lt; endl;
                        tcout &lt;&lt; "  - " &lt;&lt; publisher &lt;&lt; endl;
                        tcout &lt;&lt; "  - " &lt;&lt; version &lt;&lt; endl;
                        tcout &lt;&lt; "  - " &lt;&lt; location &lt;&lt; endl;
                        tcout &lt;&lt; endl;
                    }

                    pclsObj->Release();
                }

                pEnumerator->Release();
            }
        }
    }

    // unintializa COM
    ::CoUninitialize();
}
</pre>
<p>A sample from the output of this WmiEnum() function looks like this:</p>
<blockquote><p>
Java(TM) 6 Update 25<br />
  &#8211; Oracle<br />
  &#8211; 6.0.250<br />
  &#8211; C:\Program Files\Java\jre6\</p>
<p>Java(TM) SE Development Kit 6 Update 25<br />
  &#8211; Oracle<br />
  &#8211; 1.6.0.250<br />
  &#8211; C:\Program Files\Java\jdk1.6.0_25\</p>
<p>Microsoft .NET Framework 4 Client Profile<br />
  &#8211; Microsoft Corporation<br />
  &#8211; 4.0.30319<br />
  -</p>
<p>Microsoft Sync Framework Services v1.0 SP1 (x86)<br />
  &#8211; Microsoft Corporation<br />
  &#8211; 1.0.3010.0<br />
  -</p>
<p>Microsoft ASP.NET MVC 2 &#8211; Visual Studio 2010 Tools<br />
  &#8211; Microsoft Corporation<br />
  &#8211; 2.0.50217.0<br />
  -</p>
<p>Adobe Reader X (10.0.1)<br />
  &#8211; Adobe Systems Incorporated<br />
  &#8211; 10.0.1<br />
  &#8211; C:\Program Files\Adobe\Reader 10.0\Reader\
</p></blockquote>
<p>One can notice that the code is relatively long, but most important it is very slow.</p>
<p><strong>MSI API</strong><br />
Two of the <a href="http://msdn.microsoft.com/en-us/library/aa369426.aspx">MSI API functions</a> can help fetching the list of installed applications:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/aa370102.aspx">MsiUnumProductsEx</a>: enumerates through one or all the instances of products that are currently advertised or installed (requires Windows Installer 3.0 or newer)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa370131.aspx">MsiGetProductInfoEx</a>: returns product information for advertised and installed products</li>
</ul>
<p>In order to use these functions you need to include <strong>msi.h</strong> and link to <strong>msi.lib</strong>.</p>
<p>In the code below, MsiQueryProperty() is a function that returns the value of product property (as a tstring as defined above) by calling MsiGetProductInfoEx. MsiEnum() is a function that iterates through all the installed applications and prints in the console the name, publisher, version and installation location.</p>
<pre name="code" class="cpp">
tstring MsiQueryProperty(LPCTSTR szProductCode,
                         LPCTSTR szUserSid,
                         MSIINSTALLCONTEXT dwContext,
                         LPCTSTR szProperty)
{
    tstring value;

    DWORD cchValue = 0;
    UINT ret2 = ::MsiGetProductInfoEx(
        szProductCode,
        szUserSid,
        dwContext,
        szProperty,
        NULL,
        &#038;cchValue);

    if(ret2 == ERROR_SUCCESS)
    {
        cchValue++;
        value.resize(cchValue);

        ret2 = ::MsiGetProductInfoEx(
            szProductCode,
            szUserSid,
            dwContext,
            szProperty,
            (LPTSTR)&#038;value[0],
            &#038;cchValue);
    }

    return value;
}

void MsiEnum()
{
    UINT ret = 0;
    DWORD dwIndex = 0;
    TCHAR szInstalledProductCode[39] = {0};
    TCHAR szSid[128] = {0};
    DWORD cchSid;
    MSIINSTALLCONTEXT dwInstalledContext;

    do
    {
        memset(szInstalledProductCode, 0, sizeof(szInstalledProductCode));
        cchSid = sizeof(szSid)/sizeof(szSid[0]);

        ret = ::MsiEnumProductsEx(
            NULL,           // all the products in the context
            _T("s-1-1-0"),  // i.e.Everyone, all users in the system
            MSIINSTALLCONTEXT_USERMANAGED | MSIINSTALLCONTEXT_USERUNMANAGED | MSIINSTALLCONTEXT_MACHINE,
            dwIndex,
            szInstalledProductCode,
            &#038;dwInstalledContext,
            szSid,
            &#038;cchSid);

        if(ret == ERROR_SUCCESS)
        {
            tstring name = MsiQueryProperty(
                szInstalledProductCode,
                cchSid == 0 ? NULL : szSid,
                dwInstalledContext,
                INSTALLPROPERTY_INSTALLEDPRODUCTNAME);

            tstring publisher = MsiQueryProperty(
                szInstalledProductCode,
                cchSid == 0 ? NULL : szSid,
                dwInstalledContext,
                INSTALLPROPERTY_PUBLISHER);                

            tstring version = MsiQueryProperty(
                szInstalledProductCode,
                cchSid == 0 ? NULL : szSid,
                dwInstalledContext,
                INSTALLPROPERTY_VERSIONSTRING);

            tstring location = MsiQueryProperty(
                szInstalledProductCode,
                cchSid == 0 ? NULL : szSid,
                dwInstalledContext,
                INSTALLPROPERTY_INSTALLLOCATION);            

            tcout &lt;&lt; name &lt;&lt; endl;
            tcout &lt;&lt; "  - " &lt;&lt; publisher &lt;&lt; endl;
            tcout &lt;&lt; "  - " &lt;&lt; version &lt;&lt; endl;
            tcout &lt;&lt; "  - " &lt;&lt; location &lt;&lt; endl;
            tcout &lt;&lt; endl;

            dwIndex++;
        }

    } while(ret == ERROR_SUCCESS);
}
</pre>
<p>And this is a sample for the WmiEnum() function.</p>
<blockquote><p>
Java(TM) 6 Update 25<br />
  &#8211; Oracle<br />
  &#8211; 6.0.250<br />
  &#8211; C:\Program Files\Java\jre6\</p>
<p>Java(TM) SE Development Kit 6 Update 25<br />
  &#8211; Oracle<br />
  &#8211; 1.6.0.250<br />
  &#8211; C:\Program Files\Java\jdk1.6.0_25\</p>
<p>Microsoft .NET Framework 4 Client Profile<br />
  &#8211; Microsoft Corporation<br />
  &#8211; 4.0.30319<br />
  -</p>
<p>Microsoft Sync Framework Services v1.0 SP1 (x86)<br />
  &#8211; Microsoft Corporation<br />
  &#8211; 1.0.3010.0<br />
  -</p>
<p>Microsoft ASP.NET MVC 2 &#8211; Visual Studio 2010 Tools<br />
  &#8211; Microsoft Corporation<br />
  &#8211; 2.0.50217.0<br />
  -</p>
<p>Adobe Reader X (10.0.1)<br />
  &#8211; Adobe Systems Incorporated<br />
  &#8211; 10.0.1<br />
  &#8211; C:\Program Files\Adobe\Reader 10.0\Reader\
</p></blockquote>
<p><strong>Windows Registry</strong><br />
Installed applications are listed in Windows Registry under <strong>HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall</strong>. The <a href="http://support.microsoft.com/kb/247501">KB247501</a> article explains the structure of the information under this Registry key. Make sure you read it if you decide to use this approach. </p>
<p>In the code shown below, RegistryQueryValue() is a function that queries the value of a name/value pair in the registry and returns the value as a tstring. RegistryEnum() is a function that prints to the console all the installed application as found in the registry.</p>
<pre name="code" class="cpp">
tstring RegistryQueryValue(HKEY hKey,
                           LPCTSTR szName)
{
    tstring value;

    DWORD dwType;
    DWORD dwSize = 0;

    if (::RegQueryValueEx(
        hKey,                   // key handle
        szName,                 // item name
        NULL,                   // reserved
        &#038;dwType,                // type of data stored
        NULL,                   // no data buffer
        &#038;dwSize                 // required buffer size
        ) == ERROR_SUCCESS &#038;&#038; dwSize > 0)
    {
        value.resize(dwSize);

        ::RegQueryValueEx(
            hKey,                   // key handle
            szName,                 // item name
            NULL,                   // reserved
            &#038;dwType,                // type of data stored
            (LPBYTE)&#038;value[0],      // data buffer
            &#038;dwSize                 // available buffer size
            );
    }

    return value;
}

void RegistryEnum()
{
    HKEY hKey;
    LONG ret = ::RegOpenKeyEx(
        HKEY_LOCAL_MACHINE,     // local machine hive
        _T("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"), // uninstall key
        0,                      // reserved
        KEY_READ,               // desired access
        &#038;hKey                   // handle to the open key
        );

    if(ret != ERROR_SUCCESS)
        return;

    DWORD dwIndex = 0;
    DWORD cbName = 1024;
    TCHAR szSubKeyName[1024];

    while ((ret = ::RegEnumKeyEx(
        hKey,
        dwIndex,
        szSubKeyName,
        &#038;cbName,
        NULL,
        NULL,
        NULL,
        NULL)) != ERROR_NO_MORE_ITEMS)
    {
        if (ret == ERROR_SUCCESS)
        {
            HKEY hItem;
            if (::RegOpenKeyEx(hKey, szSubKeyName, 0, KEY_READ, &#038;hItem) != ERROR_SUCCESS)
                continue;

            tstring name = RegistryQueryValue(hItem, _T("DisplayName"));
            tstring publisher = RegistryQueryValue(hItem, _T("Publisher"));
            tstring version = RegistryQueryValue(hItem, _T("DisplayVersion"));
            tstring location = RegistryQueryValue(hItem, _T("InstallLocation"));

            if(!name.empty())
            {
                tcout &lt;&lt; name &lt;&lt; endl;
                tcout &lt;&lt; "  - " &lt;&lt; publisher &lt;&lt; endl;
                tcout &lt;&lt; "  - " &lt;&lt; version &lt;&lt; endl;
                tcout &lt;&lt; "  - " &lt;&lt; location &lt;&lt; endl;
                tcout &lt;&lt; endl;
            }

            ::RegCloseKey(hItem);
        }
        dwIndex++;
        cbName = 1024;
    }
    ::RegCloseKey(hKey);
}
</pre>
<p>And a sample output of the RegistryEnum() function:</p>
<blockquote><p>
Java(TM) SE Development Kit 6 Update 25</p>
<p>  &#8211; Oracle<br />
  &#8211; 1.6.0.250<br />
  &#8211; C:\Program Files\Java\jdk1.6.0_25\</p>
<p>Microsoft Visual Studio 2005 Tools for Office Runtime</p>
<p>  &#8211; Microsoft Corporation<br />
  &#8211; 8.0.60940.0<br />
  -</p>
<p>MSDN Library for Visual Studio 2008 &#8211; ENU</p>
<p>  &#8211; Microsoft<br />
  &#8211; 9.0.21022<br />
  &#8211; C:\Program Files\MSDN\MSDN9.0\</p>
<p>Microsoft SQL Server Compact 3.5 SP2 ENU</p>
<p>  &#8211; Microsoft Corporation<br />
  &#8211; 3.5.8080.0<br />
  &#8211; C:\Program Files\Microsoft SQL Server Compact Edition\</p>
<p>Microsoft .NET Framework 4 Client Profile</p>
<p>  &#8211; Microsoft Corporation<br />
  &#8211; 4.0.30319<br />
  -
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2011/05/01/finding-installed-applications-with-vc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add/Remove Commands to/from the Window Menu</title>
		<link>http://mariusbancila.ro/blog/2010/12/06/addremove-commands-tofrom-the-window-menu/</link>
		<comments>http://mariusbancila.ro/blog/2010/12/06/addremove-commands-tofrom-the-window-menu/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 14:38:54 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=805</guid>
		<description><![CDATA[A window&#8217;s system menu (now called simply window menu) features by default commands like Move, Size or Close. (When the user selects one of these commands a WM_SYSCOMMAND message is sent to the window.) What if you want to remove and add these commands on the fly? Here is how you can do it. This [...]]]></description>
			<content:encoded><![CDATA[<p>A window&#8217;s system menu (now called simply <em>window menu</em>) features by default commands like Move, Size or Close. (When the user selects one of these commands a <a href="http://msdn.microsoft.com/en-us/library/ms646360%28VS.85%29.aspx">WM_SYSCOMMAND</a> message is sent to the window.) What if you want to remove and add these commands on the fly? Here is how you can do it.</p>
<p>This is how a default Window menu looks for a dialog window.<br />
<img alt="" src="/blog/wp-content/uploads/2010/12/windowmenudemo1.png" title="Window Menu" class="alignnone" width="348" height="262" /></p>
<p>To remove the Move command:</p>
<pre name="code" class="cpp">
   CMenu* pSysMenu = GetSystemMenu(FALSE);
   if(pSysMenu != NULL)
      pSysMenu->RemoveMenu(SC_MOVE, MF_BYCOMMAND);
</pre>
<p><img alt="" src="/blog/wp-content/uploads/2010/12/windowmenudemo2.png" title="Move command removed" class="alignnone" width="348" height="262" /></p>
<p>To add the Move command, you can do something like this (you can also insert it at a specific position, other than 0):</p>
<pre name="code" class="cpp">
   CMenu* pSysMenu = GetSystemMenu(FALSE);
   if(pSysMenu != NULL)
      pSysMenu->InsertMenu(0, MF_BYCOMMAND, SC_MOVE, _T("Move"));
</pre>
<p><img alt="" src="/blog/wp-content/uploads/2010/12/windowmenudemo3.png" title="Move command added" class="alignnone" width="348" height="262" /></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/12/06/addremove-commands-tofrom-the-window-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No more inline ASM in VC++ on x64</title>
		<link>http://mariusbancila.ro/blog/2010/10/17/no-more-inline-asm-in-vc-on-x64/</link>
		<comments>http://mariusbancila.ro/blog/2010/10/17/no-more-inline-asm-in-vc-on-x64/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 09:02:21 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[64bit]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[porting]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[x64]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=712</guid>
		<description><![CDATA[I&#8217;m working on a project to port a 32-bit application for the x64 platform. The first errors that came up when building for x64 were related to inline ASM code, which is no longer supported in VC++ for x64. VC++ has an inline assembler built within the compiler, so you could write assembly code directly [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project to port a 32-bit application for the x64 platform. The first errors that came up when building for x64 were related to <a href="http://msdn.microsoft.com/en-us/library/4ks26t93.aspx">inline ASM code</a>, which is no longer supported in VC++ for x64. VC++ has an inline assembler built within the compiler, so you could write assembly code directly in C++ without the need of an external assembler (such as MASM). However, this works only on x86. For x64 and IA64 this is no longer possible. There are several workaround for this:</p>
<ul>
<li>put the assembly code into a separate file and use <a href="http://msdn.microsoft.com/en-us/library/hb5z4sxd.aspx">MASM for x64</a></li>
<li>use compiler intrinsics, which are functions that basically wrap assembly instructions or sequence of intructions</li>
<li>rewrite in C++, use Windows APIs, etc.</li>
</ul>
<p>One error that I had was related to this assembly code:</p>
<pre name="code" class="cpp">
   __asm {
      int 3
   }
</pre>
<p>This was used to generate a breakpoint. This can be easily replaced with compiler intrinsic <a href="http://msdn.microsoft.com/en-us/library/f408b4et.aspx">__debugbreak()</a>, which has an identical effect, except that is available on all platforms.</p>
<p>Other errors I had were due to assembly code used to retrieve the value of the EIP and EBP registers. They were used for walking the stack.</p>
<pre name="code" class="cpp">
__declspec(naked) DWORD_PTR* GetEip()
{
   __asm {
      pop   eax
      push  eax
      ret
   }
}

__declspec(naked) DWORD_PTR* GetEbp()
{
   __asm {
      mov   eax, ebp
      ret
   }
}
</pre>
<p>The naked specifier is another thing that is not supported on x64. One way to retrieve the value of these registers that works both with x86 and x64 is using RtlCaptureContext, except that this won&#8217;t work on operating system previous to Windows XP. In you don&#8217;t care about those operating systems, you could write something like this:</p>
<pre name="code" class="cpp">
      CONTEXT context;
      RtlCaptureContext(&#038;context);

#ifdef _WIN64
      DWORD_PTR* ebp = (DWORD_PTR*)context.Rsp;
      DWORD_PTR* eip = (DWORD_PTR*)context.Rip;
#else
      DWORD_PTR* ebp = (DWORD_PTR*)context.Ebp;
      DWORD_PTR* eip = (DWORD_PTR*)context.Eip;
#endif
</pre>
<p>Attention, on x64, register EBP (actually RBP) is no longer used. You should use RSP for getting the stack frame. </p>
<p>However, if you want to build a portable stack walking, use <a href="http://msdn.microsoft.com/en-us/library/ms680650%28VS.85%29.aspx">StackWalk64</a>. Despite the 64 suffix, this function works on all platforms (x86, x64, IA64). <a href="http://www.codeproject.com/KB/threads/StackWalker.aspx">Here</a> is an article that shows how to walk the stack using StackWalk64.</p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/10/17/no-more-inline-asm-in-vc-on-x64/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Just Want to Delete the Cache</title>
		<link>http://mariusbancila.ro/blog/2010/06/15/i-just-want-to-delete-the-cache/</link>
		<comments>http://mariusbancila.ro/blog/2010/06/15/i-just-want-to-delete-the-cache/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 12:31:58 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=565</guid>
		<description><![CDATA[I recently read an excerpt from Joel Spolsky&#8217;s book User Interface Design For Programmers available on his (former) blog. This is a great book about designing user interfaces, with examples of bad and good ideas. I&#8217;m getting the printed version and I recommend this to all building UIs. Now, yesterday I had a problem with [...]]]></description>
			<content:encoded><![CDATA[<p>I recently read an excerpt from Joel Spolsky&#8217;s book User Interface Design For Programmers <a href="http://www.joelonsoftware.com/uibook/fog0000000249.html">available on his (former) blog</a>. This is a great book about designing user interfaces, with examples of bad and good ideas. I&#8217;m getting the printed version and I recommend this to all building UIs.</p>
<p>Now, yesterday I had a problem with Google Documents (which no longer worked on my WinXP machine with any browser, as it continuously unsuccessfully tried to download a 237 bytes file called download.gz) and I though that deleting the cache might help. So I opened Google Chrome options dialog and then the Clear Browsing Data dialog. It looks like this.</p>
<p><img class="alignnone" title="Google Chrome - Clear Browsing Data" src="/blog/wp-content/uploads/2010/06/chromeobliterate.png" alt="" width="384" height="353" /></p>
<p>I was stunned to see the dialog started with the phrase &#8220;Obliterate the following items&#8221;. For God&#8217;s sake what is obliterating? I want to delete the cache, I don&#8217;t care about obliterating, and whatever that means. I don&#8217;t want to fetch a dictionary and look-up for the meaning of the word. Excuse me Mr. Google Programmer, that I (probably like many of the people of this world who are not native English speakers) don&#8217;t know what &#8220;obliterate&#8221; means. Yes, it does sound archaic, it does sound like J.R.R. Tolkien but it stops me doing my work. All I wanted to do was selecting what to delete and delete. Instead I spent time figuring whether that means to select what to keep or select what to delete (luckily it didn&#8217;t say purge). I had doubts so I had to search for the meaning of the word. Sure, now I know one more (fancy) English word, but overall, I lost one minute doing anything else but deleting the cache.</p>
<p>So, my recommendation to you Mr. Google Programmer is to read Joel Spolsky&#8217;s book. I&#8217;m sure there are things you can learn from it. And start using simple words and sentences that everyone understands.</p>
<p>As for what &#8220;obliterate&#8221; means, here it is:</p>
<ul>
<li>Mark for deletion, rub off, or erase</li>
<li>Make undecipherable or imperceptible by obscuring or concealing</li>
<li>Remove completely from recognition or memory</li>
<li>Do away with completely, without leaving a trace</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/06/15/i-just-want-to-delete-the-cache/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>COM and Registry</title>
		<link>http://mariusbancila.ro/blog/2010/06/01/com-and-registry/</link>
		<comments>http://mariusbancila.ro/blog/2010/06/01/com-and-registry/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 09:27:21 +0000</pubDate>
		<dc:creator>Marius Bancila</dc:creator>
				<category><![CDATA[COM]]></category>
		<category><![CDATA[Windows Programming]]></category>
		<category><![CDATA[registry]]></category>

		<guid isPermaLink="false">http://mariusbancila.ro/blog/?p=546</guid>
		<description><![CDATA[If you are working with COM there are several registry entries that are important and that you need to understand. I will try in this post to clarify them. But before that, let&#8217;s enumerate the three possible COM server scenarios. (As a side note, a COM server is a DLL or EXE can contains one [...]]]></description>
			<content:encoded><![CDATA[<p>If you are working with COM there are several registry entries that are important and that you need to understand. I will try in this post to clarify them. But before that, let&#8217;s enumerate the three possible COM server scenarios. (As a side note, a COM server is a DLL or EXE can contains one or more COM objects; a client is an entity that uses a COM object, which means a COM server can also be the client of another COM server.)</p>
<ul>
<li><strong>inproc</strong>: the COM server is loaded into the client process; in this case accessing the COM methods is as simple as using an interface pointer when the client and the in-proc server are in the same thread</li>
<li><strong>local</strong>: the COM server and the client are loaded in different processes on the same machine; communication is achieved with the use of proxies and stubs via Lightweight RPC</li>
<li><strong>remote</strong>: the COM server and the client are loaded in different processes on different machines; communication is achieved with the use of proxies and stubs via RPC</li>
</ul>
<p>In order for the COM Library to be able to locate and instantiate the COM objects correctly, different information is stored in the Windows Registry. The most important information is located under the keys CLSID, TypeLib, Interface and AppID from HKEY_CLASSES_ROOT. The images below show examples for IIS.</p>
<p><strong>HKEY_CLASSES_ROOT\CLSID</strong><br />
Every coclass from the COM server has at least an entry under this key, specifying the CLSID and the ProgID. The CLSID is a GUID that uniquely identifies the class, and the ProgID (programmatic identifier) is a string that identifies the class in a more human readable form. Each ProgID is mapped to a CLSID. The following image shows the mapping for the IIS ProgID.<br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_clsid1.png" title="IIS ProdID" class="alignnone" width="795" height="296" /></p>
<p>For each COM class, there must be a key under HKEY_CLASSES_ROOT\CLSID, with the CLSID as the name. The most important sub-keys here are:</p>
<ul>
<li><strong>ProgID</strong>: the programmatic identifier, mapped on the CLSID; cam contain a version number (as a suffix)</li>
<li><strong>VersionIndependentProgID</strong>: a programmatic identifier without the version information</li>
<li><strong>InprocServer32</strong>: specifies the path of the DLL for the inproc servers</li>
<li><strong>LocalServer32</strong>: specifies the path of the COM executable for the local (out-of-process) servers</li>
<li><strong>TypeLib</strong>: indicates the LIBID of the type library that contains the coclass</li>
</ul>
<p>Here are several screenshots from registry for IIS CLSID.<br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_clsid2.png" title="IIS InprocServer32" class="alignnone" width="795" height="296" /><br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_clsid3.png" title="IIS ProgID" class="alignnone" width="797" height="295" /><br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_clsid4.png" title="IIS TypeLib" class="alignnone" width="795" height="296" /></p>
<p><strong>HKEY_CLASSES_ROOT\TypeLib</strong><br />
Each type library has a key under HKEY_CLASSES_ROOT\TypeLib, with the name of the LIBID. The sub-keys provide information about the physical location of the type library file (.tlb file) and others, such as flags (FLAGS key) the directory that contains the help file for the type library (HELPDIR key). A LIBID is a GUID that uniquely identifies a type library. A *.TLB file is a binary version of an IDL file. This is used by languages such as VB, Java, Javascript and many others in order to be able to use the COM objects.</p>
<p>The following image shows the type lib information for IIS.<br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_typelib.png" title="IIS Typelib" class="alignnone" width="795" height="296" /></p>
<p><strong>HKEY_CLASSES_ROOT\Interface</strong><br />
Information for all interfaces defined in an IDL file (type library) must be added to the registry. Under HKEY_CLASSES_ROOT\Interface must be a key with the IID of the interface. The IID (interface identifier) is a GUID that uniquely identifies an interface. The most important sub-keys are:</p>
<ul>
<li><strong>TypeLib</strong>: the LIBID of the type library containing the interface</li>
<li><strong>ProxyStubClsid32</strong>: the CLSID of the marshaller used to marshal the interface; value <em>{00020424-0000-0000-C000-000000000046}</em> identifies oleaut32.dll, which is the universal marshaler.</li>
</ul>
<p>The following images show the registry entry for the interface IISBaseObject.<br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_interface1.png" title="IIS interfaces" class="alignnone" width="795" height="296" /><br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_interface2.png" title="IIS interfaces" class="alignnone" width="795" height="296" /></p>
<p><strong>HKEY_CLASSES_ROOT\AppID</strong><br />
An AppID (application identifier) is a GUID that uniquely identifies a COM server and is used to describe security and activation settings; it is used for out-of-proc (local or remote) scenarios. Usually the AppID is the same with a CLSID of a coclass from the COM server (without the risk of collision, because the CLSID and the AppID server different purposes). The most important settings are:</p>
<ul>
<li><strong>AccessPermission</strong>: defines the ACL of users that can access the server</li>
<li><strong>AuthenticationLevel</strong>: defines the authentication level</li>
<li><strong>DllSurrogate</strong>: identifies the surrogate that can host the DLL; if no value is specified, the default dllhost.exe surrogate is used</li>
<li><strong>LaunchPermissions</strong>: defines the ACL of users that can launch the application</li>
<li><strong>RemoteServerName</strong>: identifies the remove server machine</li>
</ul>
<p>The following images shows the values for an AppID key.<br />
<img alt="" src="/blog/wp-content/uploads/2010/06/comreg_appid.png" title="AppID example" class="alignnone" width="797" height="295" /></p>
]]></content:encoded>
			<wfw:commentRss>http://mariusbancila.ro/blog/2010/06/01/com-and-registry/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

