Coding to the Windows SDK

In the near future I’ll be posting code examples that compile and run.  In case you’d like to follow along, here’s my personal setup.  My code should compile on RC1 also, so go ahead and use RC1 if that’s what you can get a hold of.

  1. Windows Vista Sept CTP (Build 5728)
  2. The matching Windows SDK Sept CTP
  3. Visual Studio 2005 C++ Express Edition

RC1 NOTE: If you have Windows Vista RC1, be sure to grab the matching Windows RC1 SDK.  The versions must match or you will get runtime errors. 

The best thing is, you can get all these downloads for FREE!    RC1 will expire in July 2007 but it’s a good way to play with Vista before it ships.

The first thing to do is point Visual Studio at the Windows SDK.  Click Tools->Options…->Projects and Solutions->VC++ Directories and insert the following directories at the top of each list.  I’m a purist, so I removed the other directories too, but you probably don’t have to do that.

RC1 NOTE: The RC1 SDK for some reason installs its files to a v1.0 directory.  Adjust the paths below accordingly.

  • Executable files:

    • G:\Program Files\Microsoft SDKs\Windows\v6.0\VC\Bin
    • G:\Program Files\Microsoft SDKs\Windows\v6.0\Bin
    • $(PATH)

  • Include files:

    • G:\Program Files\Microsoft SDKs\Windows\v6.0\VC\Include
    • G:\Program Files\Microsoft SDKs\Windows\v6.0\Include

  • Library files:

    • G:\Program Files\Microsoft SDKs\Windows\v6.0\VC\Lib
    • G:\Program Files\Microsoft SDKs\Windows\v6.0\Lib

  • Source files:

    • G:\Program Files\Microsoft SDKs\Windows\v6.0\VC\Include
    • G:\Program Files\Microsoft SDKs\Windows\v6.0\Include

  • Exclude directories:

    • G:\Program Files\Microsoft SDKs\Windows\v6.0\VC\Include
    • G:\Program Files\Microsoft SDKs\Windows\v6.0\Include

As a purist, I like to start with empty C++ console applications.  Let’s create one and create propshow.cpp.  I’ll fill this file out later, but for now, let’s just type:

#include <windows.h>
#include <propsys.h>
#include <propvarutil.h>
#include <propkey.h>
#include <stdio.h>

#pragma comment(lib, “propsys.lib”)
#pragma comment(lib, “ole32.lib”)

int wmain(__in int argc, __in_ecount(argc) WCHAR **argv)
if (SUCCEEDED(hr))
PROPVARIANT propvar = {0};
hr = InitPropVariantFromUInt32(RATING_FOUR_STARS_SET, &propvar);
if (SUCCEEDED(hr))
WCHAR szValue[100] = L”\0″;
hr = PSFormatForDisplay(PKEY_Rating, propvar, PDFF_DEFAULT, szValue, ARRAYSIZE(szValue));
if (SUCCEEDED(hr))
wprintf(L”The rating is %s.\n”, szValue);

That’s it!  Compile, run, and it should print “The rating is 4 Stars.”

-Ben Karas

Comments (3)

  1. PatriotB says:

    It’s interesting that you expliclity pass COINIT_DISABLE_OLE1DDE to CoInitializeEx; I’ve never really seen it used before.  Is it something that we "should" usually do?  I’m guessing it helps reduce attack surface area or something?

  2. benkaras says:

    I got COINIT_DISABLE_OLE1DDE and the neat pragma tricks from .  I assume that there is a slight performance gain from disabling OLE1DDE on the current thread.  

     [Update 2006/10/03]

    I talked with ChrisG about his reasoning behind this flag.  To quote him: 

    “This is a minor optimization that avoids the creation and init of some state that exists to support OLE1 apps. OLE1 was a pre COM technology that used DDE as the IPC.<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” />


    Generally all code should use this flag.”

  3. This coding expedition has developed a tool that can dump out all the properties on a file. If you are