Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Windows 7 Managed Code APIs

19 May 2009   #1

Windows 10 Workstation x64
Windows 7 Managed Code APIs

We have enabled an easy direct access to Windows 7 (and some Windows Vista) features for .NET developers. All you need to do is download Windows API Code Pack today!

As mentioned in the Windows 7 .NET Interop Sample Libraries post, most Windows 7 APIs are written in native code C, C++, and COM APIs, and have no .Net equivalents. This makes the life of managed code developers a bit hard, forcing them to create their own interoperability layers for communicating between .NET and the native Windows APIs. Some native APIs are easy to wrap and use from managed code, requiring simple interoperability efforts like adding a reference to a COM type library. However, some are extremely problematic and require a lot of knowledge about the “Win32” programming style. That is exactly why the Windows API Code Pack for Microsoft .NET Framework was created.

In the Windows 7 .NET Interop Sample Libraries post, we highlighted few samples codes showing how to access the Taskbar, Libraries, Sensor, and multi-touch from .NET, and we also promised to report in the near future on a new project, Windows API Code Pack for Microsoft .NET Framework. The Windows SDK team built the Windows API Code Pack to provide easy access to Windows 7 features for .NET developers , lowering the bar for developers who want to target Windows 7 Client applications. Basically, it is the closest thing a .NET developer will have to managed code APIs for Windows 7.

The Windows API Code Pack (Code Pack) is much larger in terms of offered functionality and quality than its older brother, the Windows Vista Bridge. The Code Pack contains a wide variety of APIs, including very comprehensive Windows Shell namespace objects, Windows Taskbar, Libraries, and Windows 7 Extended Linguistic Services. The following is a short list of the APIs contained in the Windows API Code Pack:

  • Support for Windows Shell namespace objects, including:
    • Windows 7 libraries
    • Known Folders
    • Non-file system containers
  • Windows Vista and Windows 7 Task Dialogs
  • Support for Windows 7 Explorer Browser Control
  • Support for Shell property system
  • Windows 7 Taskbar
  • Support for Windows Vista and Windows 7 common file dialogs, including custom file dialog controls
  • Support for Direct3D 11.0 and DXGI 1.0/1.1 APIs
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
When you download and unzip the v0.85 file, you will find a Samples folder. This folder contains number of samples demonstrating the entire range of APIs provided by the API Code Pack. You will also find the WindowsAPICodePack folder that contains the full source code for this library. This provides a great interoperability learning opportunity, while giving you the full flexibility of changing source code.

There are many samples, 13 for now with more coming in future releases, but there are four in particular that I want to highlight.

WPF Explorer Browser Demo

Before going into details about this demo, let’s talk about the Windows Shell. The Windows Shell is the main area of user interaction in Windows. Many users refer to the Windows Explorer as “Windows”; however, it is just one part of the overall Windows Shell. The shell includes many other UI elements, such as the Taskbar, the Start Menu, Windows Explorer windows, the Recycle Bin, and search results. The most common and well known shell objects are files and folders. However, there are many other virtual objects such as the Recycle Bin, printers, Libraries, etc. Shell objects are organized into a hierarchical namespace that encompasses the file system namespace.

With a proper understanding of the Shell namespace, and access to the topmost Shell Object, the Desktop, you can traverse the entire computer, including files and folders, as well as printers, fonts, Program files, and Recorded TV. By using the Shell namespace, developers can access all the files and folders and all the Known Folders (which we briefly mentioned in the Libraries Under the Hood post) in a given computer.

Up until now, this was blocked from .Net developers; however, the new Code Pack provides an Explorer Browser control as well as well the defined objects, structs, and APIs needed to traverse the Shell namespace. In the Shell part of the Code Pack (Shell project), you can find Explorer Browser controls for WPF and WinForms, as well as all the functionality needed to work with Known Folders, and a wide range of Shell objects (under the Common folder) such as ShellObject, ShellLink, ShellFolder, ShellItem, ShellCollection, ShellThumbnail, and the list continues. The Taskbar and Libraries implementation also uses many of these shell objects. As shown in the following picture, the Explorer Browser demo spotlights the Explorer Browser control that can help visualize the Shell namespace.

Similarly, Shell Hierarchy Tree Demo, shows how you can traverse the entire computer contents using the Shell namespace starting from the topmost Desktop objects:


The Code Pack also contains Sensor APIs for the Windows 7 Sensor and Location platform. The Sensor project contains all the necessary definitions to work with Sensors including a SensorManager to get sensors, and a Sensor class to work with sensors, and of course a SensorReport that allows you to access the sensor data. The Sensor demos include two demos illustrating two sensors, Light and Motion. You can use the Virtual Light Sensor from Win 7 RC SDK to simulate different lighting conditions, and the very simple Ambient Light Level application to display a visual representation of the total amount of light detected by the light sensor.

Extended Linguistic Services Demo

Extended Linguistic Services (ELS) is another very interesting technology available in Windows 7. ELS is a new feature in Windows 7 that allows developers to use the same small set of APIs to leverage a variety of advanced linguistic functions. By using ELS APIs in Windows 7, developers can auto-detect the language of any piece of Unicode text and use that information to make smarter user experience choices for customers around the world. The ELS platform is the interface between your application and ELS services. It provides a simple way to leverage several kinds of linguistic functionality through the same API, which allows the application to access and use specific services. For more information about the API, see Extended Linguistic Services Reference.

By using the MappingAvailableServices class you can query a given string for the language in which the string is written. This allows you to either verify the language in which a string is written or ask in what language a string is written. This can be a very powerful tool for multi-language application developers.

And it is easy to use. For example, the following line of code tries to detect what languages are used in the string:

scriptDetection.RecognizeText("This is English. .", null)) The output will be something like:

Recognized 2 script ranges

Range from 0 to 16, script Latn

Range from 17 to 22, script Cyrl

Taskbar and Libraries

The Code Pack provides the required APIs to program against the Taskbar and Libraries in Windows 7. For the Taskbar you can:
  • Create and manipulate JumpLists, including tasks and items
  • Display Dynamic Overlay Icons, Thumbnail Toolbars
  • Use the Taskbar progress bar
At this stage of the development, you cannot Control Custom Thumbnail Preview, and custom Preview, also known as AeroPeek. To have this functionality, you will need to use the Windows 7 Taskbar Sample .NET Interop Library.

With the Taskbar demo, you can learn how to have full control over your Jump List as shown in the next image:

The Code Pack also provides full support for Windows 7 Libraries, which we will talk about extensively in the next post.

Please note that this library is currently a work-in-progress and this is version 0.85 of this library. The final version of this library will be available around the time of the Windows 7 RTM release. Please help us improve by downloading the source code and sample, and using them in your applications. Please report bugs or any other comments and ideas you might have using the Discussion, and Issue Tracker.


My System SpecsSystem Spec

 Windows 7 Managed Code APIs

Thread Tools

Similar help and support threads
Thread Forum
When I go on the Microsoft site I can no longer find where the APIs are listed. Does anyone else have this problem?
General Discussion
Unhandled exception in Managed Code Snap-In (?????)
This problem falls under the old vaudeville joke "Doc, it hurts when I do this / well then don't do this"... Last night, for the second time in about a month, I got a BSOD during my normal restart Windows sequence I do at the end of the night (the BSOD occurs after the programs close, the...
Performance & Maintenance
Windows APIs: Microsoft's hidden guide to architecture
Read more at source: Windows APIs: Microsoft's hidden guide to architecture | ZDNet
Windows 7 Libraries – Managed Code
Windows 7: UAC whitelist. Secret APIs again. A lawsuit waiting to happen?
Windows 7: UAC whitelist. Secret APIs again. A lawsuit waiting to happen? This is message written by a mod at the unofficial forum for Directory Opus, a 3rd party Windows file manager. It's a interesting little read, especially since I am a Directory Opus user myself :huh:

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 10:30.
Twitter Facebook Google+