Fix Error: An attempt was made to load a program with an incorrect format

Thursday, September 16, 2010

While trying to run the sample project ShellObjectWatcherSampleWPF from the latest version of Windows API Code Pack, I came across the following problem, both in Visual Studio 2008 and 2010: Or in a search-engine friendly way: “Cannot create instance of ‘MainWindow’ defined in assembly, ‘ShellObjectWatcherSampleWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Exception has been thrown by the target of an invocation.  Error in markup file ‘MainWindow.xaml’ Line 1 Position 9.” Checking the internal exception, revealed the following: "Could not load file or assembly 'Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An...

Windows API Code Pack v1.1 Released!

Monday, September 13, 2010

Last Tuesday (31.08.2010) Microsoft released a new version for the excellent managed library, Windows API Code Pack. For those who don’t know, this library serves as a managed wrapper for many Windows APIs which are not included in .NET framework, especially new features from Windows Vista and Windows 7. I’ve been working with this library for quite some time now and I must say it is “.NET missing piece”. Most of Windows features which doesn’t exists in .NET are at your fingertips =, without handling all the Interop stuff yourself. With the coming of .NET Framework...

Using Windows 7 Light Sensor in Your Application

Tuesday, June 29, 2010

One of the new features we got with Windows 7 is a the Windows Sensor and Location Platform. This platform enables us, developers, to access a variety of sensors with a standard API. No more rewrite-entire-device-layer-because-we-changed-vendors issues. All that is required is that the hardware vendor will provide a Windows 7 compliant driver. Microsoft practically opened this market to competition, so we can expect allot of these sensors in the coming future. Ambient Light Sensor One sensor type which becomes increasingly poplar with laptops is the Ambient Light Sensor. This sensor type measures the amount of light in the computer surroundings. There...

Application Recovery and Restart C# Quick Reference

Tuesday, April 20, 2010

Background Application Recovery and Restart (ARR) is a feature that allows you to prepare for the impossible (?) case where your application crash or waits forever (“Not Responding”) The feature lets you “register” for these cases in order to give you the opportunity to save the application data or do some clean up operations, before it ends its life. This feature exists from Windows Vista, but it seems that not enough people knows it, so let’s see how can anyone use the Windows API Code Pack to easily integrate ARR in their applications. More information on the feature can be found at Application...

Windows 7 Libraries C# Quick Reference

Monday, March 15, 2010

Following are some listings to be used as a quick reference to common Windows 7 Libraries features using Windows API Code Pack. The code in this post is based on previous work by Alon and other Sela team members. Great work all. Forward Just to clarify the terminology used: Every Windows 7 library is represented as an XML file with the .library-ms extension. The common libraries files are commonly stored in: C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Libraries\ So if, for example, we work now with the Pictures library, than in the following sections: libraryName = Pictures locationPath = C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Libraries\ Note: you can create library files wherever you want, not...

Windows 7 Taskbar C# Quick Reference

Tuesday, March 9, 2010

Following are some listings to be used as a quick reference to common Windows 7 Taskbar features using Windows API Code Pack. The code in this post is based on previous work by Yochay and Sasha. Features Setting the process Application ID TaskbarManager.Instance.ApplicationId = "TaskbarManaged"; Note: This should be done before the window is shown, a good place is on form load. Setting the Application ID of a window TaskbarManager.Instance.SetApplicationIdForSpecificWindow(form.Handle, "SomethingElse"); or in WPF: TaskbarManager.Instance.SetApplicationIdForSpecificWindow(wpfWindow, "SomethingElse"); Adding a file into the Recent category on the JumpList  _jumpList = JumpList.CreateJumpList(); ... _jumpList.AddToRecent(filePath); Note: You must register (associate) the file type with your application for this to work. Note 2: If you use the common...

Windows Ribbon for WinForms, Part 0 – Table of Contents

Wednesday, December 23, 2009

First I want to announce that the Windows Ribbon for WinForms library is no longer beta. Since now the library covers every feature available by the windows ribbon I think it would be useful to provide a table of contents for the posts I've written during the development process. Each post serves as documentation on how to use one or two ribbon features. Windows Ribbon for WinForms, Part 1 – Introduction: Background on the windows ribbon. Windows Ribbon for WinForms, Part 2 - Basic Ribbon Wrapper: Basic .NET wrappers for windows ribbon. Windows Ribbon for WinForms, Part 3 - First WinForms...

Setting Decimal value on PropVariant

Friday, October 16, 2009

PROPVARIANT is Important PROPVARIANT is an important COM structure that is used in many windows shell features like: Shell Namespace Extensions, Taskbar Jump List, Sensors and Windows Ribbon Framework, just to name a few. In order to use these shell features in managed code, one must provide a .NET wrapper for this struct. Now, you might have expected that if this struct is so important, there would be good .NET wrappers for it.. Unfortunately, this is not the case. The problem with this struct is that it is pretty...

Windows Ribbon for WinForms, Part 3 – First WinForms Ribbon Application

Tuesday, September 15, 2009

So let's see how to use the Ribbon class to add ribbon support to an empty WinForms application. Step 0 – Download Windows Ribbon for WinForms As I’ve mentioned in previous posts, you can download the code for my ribbon wrapper library along with numerous samples (currently one..) from windowsribbon.codeplex.com Also, I remind you to download the helper library, Windows API Code Pack. Update (18.11.2009): The project doesn’t depends anymore on Windows API Code Pack. In this post I'll review how to create your...

Windows Ribbon for WinForms, Part 2 – Basic Ribbon Wrapper

Sunday, September 13, 2009

Today we will start looking at some code, but before we begin you might want to know where to find it. The most updated version of "Windows Ribbon for WinForms" code will be at http://windowsribbon.codeplex.com/ It will include the latest version of the project code and samples of how to use its different features. Note that it is based on the Windows API Code Pack, so make sure you have it if you plan to compile the code. Update (18.11.2009): The Windows Ribbon for WinForms project is not dependent on Windows API Code Pack...