Maestro / C# - Unable to load DLL 'Winusb.dll'

Hello everyone !

I have a small issue and somehow cannot find out where it come from.

I am developing a small program in C# to control a Maestro 6 port controller. As i am using the USB sdk provided, everything works great, Easy example and Advanced alike. However when i reference the DLLs in my own project, i always get this WINUSB.DLL missing, and i have no clue why.

I stripped the program to the minimum to show you:

using Pololu.Usc;
using Pololu.UsbWrapper;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace ConsoleApplication1
    public class Program
        static void Main(string[] args)
            TrySetTarget( 0, 2000*4 );

        static void TrySetTarget(Byte channel, UInt16 target)
                using (Usc device = connectToDevice()) 
                    device.setTarget(channel, target);

            catch (Exception exception)

        static Usc connectToDevice()
            List<DeviceListItem> connectedDevices = Usc.getConnectedDevices();

            foreach (DeviceListItem dli in connectedDevices)

                Usc device = new Usc(dli); 
                return device;             
            throw new Exception("Could not find device.  Make sure it is plugged in to USB " +
                "and check your Device Manager (Windows) or run lsusb (Linux).");

As you can see this is pretty much copy paste from the example, but in a ‘fresh’ console project. Both Usc and UsbWrapper are referenced (the basic way, is there another ?). The Usc.getConnectedDevices() find the proper Maestro ID as well, the problem happen at Usc device = new Usc(dli); i think

Now the TrySetTarget() method called in the Main() will give me this error:

“Unable to load DLL ‘winusb.dll’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)”

And as i said, the actual examples are working fine…

Any idea? :question:

What version of Visual Studio are you using? What version of Windows are you using? Is it 32-bit or 64-bit?

Since the examples worked, winusb.dll is probably in the right place, but just to be sure, please check to make sure that winusb.dll is present in C:\Windows\System32.

Probably your project is not configured correctly. Just to be clear: you don’t need to add a reference for winusb.dll, so in case you did that you should remove it. I recommend looking carefully at all configuration options of the example project that worked and comparing it to the configuration of your project.

Did you create your new project within the existing Usc.sln solution in the Pololu USB SDK, or did you make it somewhere else from scratch?

Did you reference the precompiled Usc.dll in Maestro\Usc\precompiled_obj, or did you reference a Usc.dll that you compiled yourself, or did you just reference the Usc.csproj project?


Thanks for your quick reply David, I am really puzzled by this…

For information, I am using Visual C# Express 2010, at the moment on WinXP x64, but also Win7 x64… Winusb.dll is where it should be and its not referenced (and not reference-able). The Usc.dll and UsbWrapper.dll referenced are the pre-compiled ones, same ones as the example files.

When i run the project step by step, the exception happen when i reach this function in the Usc.cs file:

public Usc(DeviceListItem deviceListItem) : base(deviceListItem)
            // Determine the number of servos from the product id.
                case 0x89: servoCount = 6; break;
                case 0x8A: servoCount = 12; break;
                case 0x8B: servoCount = 18; break;
                case 0x8C: servoCount = 24; break;
                default: throw new Exception("Unknown product id " + getProductID().ToString("x2") + ".");

This seems to be what is throwing the exception.

Now if i copy/paste my own code into the example project, my code actually runs fine, so you are right saying the problem lies in the configuration of the project or its references, but i can’t find anything relevant.

Keeping searching, it seems (but not sure) the issue comes from a x86 / x64 incompatibility… I am not sure how to setup the processor type at this point, will look into it.

Ok, so it is a x86 / x64 issue.

First to be able to fool around with the processor settings in a fresh new project, one must activate the
Show advanced build configurations.
Tool -> Options -> Projects and Solutions -> General

Once this is done, you can see the configuration which by default is Debug | x86
Now on my system this config will give me the winusb.dll error mentioned in the first post. If i switch to Any CPU or x64 then the error goes away, so that’s good. However that’s not what i want because my other libraries start behaving wrong then, specially the WIA library that remote control my camera that is part of the contraption i’m coding for.

Any suggestions ?

Ok again, after further testing the issue cannot be reproduced with Windows 7 64bit, the winusb.dll error will not happen not matter what processor configuration is used. And the WIA error either. It’s all XP 64bit related.

Well it still leave this bug under Windows XP 64bit but i guess the platform is too old and irrelevant for the Pololu team to look into it.


Thanks for posting your debugging results, and I’m glad you got it working consistently on Windows 7 64bit. It is my impression that Windows XP 64bit is too old and irrelevant for even Microsoft to work on much. There have been a couple of USB bugs over the years that have been patched in 32bit Windows XP that haven’t made it into 64bit.

- Ryan

That’s correct Ryan, the bug cannot be reproduced with XP 32bits either…

Thanks for the help !

Until the next issue… Bye