2010-12-04

Where does Windows device enumeration actually begin?

That's in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum.

i.e., the PCI\ USB\ HID\ branches of a Device Instance ID path all originate from ControlSet\Enum.

2010-12-02

That darn "libtoolize: AC_CONFIG_MACRO_DIR([m4]) conflicts with ACLOCAL_AMFLAGS=-I m4" error

Is caused by using CRLFs in Makefile.am. "m4<CR>" != "m4" and thus the libtoolize script will produce an error.

If you're using git, I strongly advise adding a .gitattributes file with the following:
*.sh     -crlf
*.ac     -crlf
*.am     -crlf

2010-08-31

Finally *REAL* eSATA

A.k.a. eSATAp.

What kind of moronic committee, who's mysteriously silent on eSATAp (when others have to step in and fix failures behind your back, yes, you do deserve epithets) designs a connector for external HDDs, as well as other external devices, that does not provide Power by default, especially after USB has been doing it for years.
Probably too little, too late. Still, I'd rather have eSATAp with a $15 bracket & cable, than USB 3.0 for external HDDs. When transferring data, the most straightforward solution is always the best.

2010-08-13

Schematics for a PIC 18F2550 based USB demo board


Click on the image above for the PDF schematic for a Microchip PIC 18F2550 based USB demo board, with a TTL serial port (also in .ai format).

Or, since I'm reusing their design and also have been using one of their cheap PICKit2 Kit board, I'll mention that you can also buy a more elaborate ready to assemble version of the above demo board from fun4diy.com, that doubles as a PICKit2. Note however that if you use that PICKit2 "Kit" and want serial I/O, you'll have to modify the board a little (but you can use the unused U4 pins for that).

If you're testing USB, such a demo board is very convenient to have, and most of the PIC 18F4550 firmwares you'll see can be easily ported to 16F2550. I'll try to post more about that when I get a chance.

2010-07-14

Installing MinGW-w32 on a Windows system

Edit: As of 2011, the information below should only apply if for whatever reason, you cannot use <code>mingw-get</code> for your installation needs. If you are looking for a quick and easy way to install MinGW, you should use <code>mingw-get</code>, either in its GUI version or its command line version.

This is pretty much a reformatting of this post by Xiaofan for the purpose of building libusb and similar projects
  1. Install 7-zip from http://www.7-zip.org as all the MSYS/MinGW are provided in LZMA format. Make sure you go to Options -> System and set the .lzma file association.
  2. Chose a SourceForge mirror from this list and make sure you bypass SourceForge super annoying interface, by browsing project directories in an FTP like fashion. For instance, you can use http://ftp.heanet.ie/mirrors/sourceforge/m/project/mi/mingw to get access to the files fast.
  3. Create both an msys and MinGW directories, on one of your disks, preferably at the root level. For instance, if you install to C, you should create C:\MinGW and C:\msys
  4. In the following list items, I will list the current directory you should download the files from at the root level, and the files to download at the item level. With regards to the extraction, you should extract the files into the same directory as the root for the download (eg. MinGW/BaseSystem/GCC/Version4/gcc-4.5.0-1/gcc-core-4.5.0-1 -> C:\MinGW). Note that the archives are an lzma of a tar, so in 7-zip, you should double click until you see the directories like bin/, include/ etc. These are the directories that need to be copied over to the MinGW or msys dir, so make sure you extract at the right level.
  5. MinGW/BaseSystem/GCC/Version4/gcc-4.5.0-1/
    • gcc-core-4.5.0-1-mingw32-bin.tar.lzma 
    • gcc-c++-4.5.0-1-mingw32-bin.tar.lzma 
    • libgcc-4.5.0-1-mingw32-dll-1.tar.lzma
    • libstdc++-4.5.0-1-mingw32-dll-6.tar.lzma
    • libssp-4.5.0-1-mingw32-dll-0.tar.lzma
  6. MinGW/BaseSystem/GNU-Binutils/binutils-2.20.51/
    • binutils-2.20.51-1-mingw32-bin.tar.lzma
  7. MinGW/gmp/gmp-5.0.1-1/
    • libgmp-5.0.1-1-mingw32-dll-10.tar.lzma
  8. MinGW/mpc/mpc-0.8.1-1/
    • libmpc-0.8.1-1-mingw32-dll-2.tar.lzma
  9. MinGW/mpfr/mpfr-2.4.1-1/
    • libmpfr-2.4.1-1-mingw32-dll-1.tar.lzma
  10. MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-3.18/
    • mingwrt-3.18-mingw32-dll.tar.gz
    • mingwrt-3.18-mingw32-dev.tar.gz
  11. MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-3.14/
    • w32api-3.14-mingw32-dev.tar.gz
  12. MSYS/BaseSystem/msys-1.0.15-1/
    • msysCORE-1.0.15-1-msys-1.0.15-bin.tar.lzma
    • msysCORE-1.0.15-1-msys-1.0.15-ext.tar.lzma (this is the file containing the postinstall script we need to run) 
  13. MSYS/autoconf/autoconf-2.65-1/
    • autoconf-2.65-1-msys-1.0.13-bin.tar.lzma
  14. MSYS/autogen/autogen-5.10.1-1/
    • autogen-5.10.1-1-msys-1.0.15-bin.tar.lzma
    • libopts-5.10.1-1-msys-1.0.15-dll-25.tar.lzma
  15. MSYS/automake/automake-1.11.1-1/
    • automake-1.11.1-1-msys-1.0.13-bin.tar.lzma
  16. MSYS/bash/bash-3.1.17-3/
    • bash-3.1.17-3-msys-1.0.13-bin.tar.lzma
  17. MSYS/console/console-2.00b146-1/
    • console-2.00b146-1-msys-1.0.14-bin.tar.lzma
  18. MSYS/coreutils/coreutils-5.97-3/
    • coreutils-5.97-3-msys-1.0.13-bin.tar.lzma
    • coreutils-5.97-3-msys-1.0.13-ext.tar.lzma
  19. MSYS/crypt/crypt-1.1_1-3/
    • libcrypt-1.1_1-3-msys-1.0.13-dll-0.tar.lzma
  20. MSYS/gawk/gawk-3.1.7-2/
    • gawk-3.1.7-2-msys-1.0.13-bin.tar.lzma
  21. MSYS/gdbm/gdbm-1.8.3-3/
    • libgdbm-1.8.3-3-msys-1.0.13-dll-3.tar.lzma
  22. MSYS/gettext/gettext-0.17-2/
    • gettext-0.17-2-msys-1.0.13-bin.tar.lzma
    • libasprintf-0.17-2-msys-dll-0.tar.lzma
    • libgettextpo-0.17-2-msys-dll-0.tar.lzma
    • libintl-0.17-2-msys-dll-8.tar.lzma
  23. MSYS/grep/grep-2.5.4-2/
    • grep-2.5.4-2-msys-1.0.13-bin.tar.lzma
  24. MSYS/libiconv/libiconv-1.13.1-2/
    • libcharset-1.13.1-2-msys-1.0.13-dll-1.tar.lzma
    • libiconv-1.13.1-2-msys-1.0.13-dll-2.tar.lzma
  25. MSYS/libtool/libtool-2.2.7a-2/
    • libtool-2.2.7a-2-msys-1.0.13-bin.tar.lzma
    • libltdl-2.2.7a-2-msys-1.0.13-dll-7.tar.lzma
  26. MSYS/m4/m4-1.4.14-1/
    • m4-1.4.14-1-msys-1.0.13-bin.tar.lzma
  27. MSYS/make/make-3.81-3/
    • make-3.81-3-msys-1.0.13-bin.tar.lzma
  28. MSYS/patch/patch-2.6.1-1/
    • patch-2.6.1-1-msys-1.0.13-bin.tar.lzma
  29. MSYS/perl/perl-5.6.1_2-2/
    • perl-5.6.1_2-2-msys-1.0.13-bin.tar.lzma
  30. MSYS/sed/sed-4.2.1-2/
    • sed-4.2.1-2-msys-1.0.13-bin.tar.lzma
  31. MSYS/tar/tar-1.23-1/
    • tar-1.23-1-msys-1.0.13-bin.tar.lzma
  32. MSYS/termcap/termcap-0.20050421_1-2/
    • libtermcap-0.20050421_1-2-msys-1.0.13-dll-0.tar.lzma
    • termcap-0.20050421_1-2-msys-1.0.13-bin.tar.lzma
  33. MSYS/zlib/zlib-1.2.3-2/
    • zlib-1.2.3-2-msys-1.0.13-dll.tar.lzma
  34. MSYS/cvs/cvs-1.12.13-2/
    • cvs-1.12.13-2-msys-1.0.13-bin.tar.lzma
  35. MSYS/file/file-5.04-1/
    • file-5.04-1-msys-1.0.13-bin.tar.lzma
    • libmagic-5.04-1-msys-1.0.13-dll-1.tar.lzma
  36. MSYS/gzip/gzip-1.3.12-2/
    • gzip-1.3.12-2-msys-1.0.13-bin.tar.lzma
  37. MSYS/regex/regex-1.20090805-2/
    • libregex-1.20090805-2-msys-1.0.13-dll-1.tar.lzma
  38. double click msys.bat
  39. navigate to c/msys/postinstall
  40. run ./pi.sh and follow the prompts

2010-07-11

Compiling MinGW-w64 with multilib on Linux

In this post, I'll describe how to manually get a version of MinGW-w64 that (should) supports multilib (i.e. -m32 & -m64, to produce either 32 or 64 bit Windows binaries), as well as static and shared library generation on a Linux host platform, using the current latest official versions of everything. Most of what I'm going to describe is based on the mingw-w64-howto-build guides that one can find here, with fixes added. This guide is intended to be fairly generic, so that you can use it as a base for more specific settings.

Disclaimer

First of all, a bit of a warning. If you have anything urgent coming up, if your boss wants something else done by tomorrow or if you have a wife & kids requiring your attention, do not start building a cross compiler manually! You should only ever do so if you can totally waste a couple of days trying to figure out how to fix that £$%^& non working cross compilation process. As you will see soon enough, gcc is a pretty wild beast when it comes to cross compilation, and no matter what you do or which guide you follow, you're pretty much guaranteed that it's going to be anything but a smooth ride. If you don't have time to waste, there are scripts here and there that should take care of taming the beast for you. Of course, these scripts won't usually let you pick up the very latest versions, as we are going to do here, but you can't have it all. Also, of course, I make no guarantee whatsoever that what I'm describing below will actually work for you. You have been warned!


Downloads & Prerequisites

As you should know, there's a bit more to compiling MinGW than just picking up the latest MinGW and gcc. You also need binutils and gcc also relies on a few libraries, so below is the list of everything you'll need, with the latest versions available at the time of this post (2010.07.10):
All of the above are the current very latest official versions.

You will also need some disk space (preferably on a fast "disk" device) in the range of 2 to 3 GB for the whole compilation process. Better create a working directory and download everything here. Everything apart from MinGW itself can be gotten using wget or your preferred method of download, so you should go ahead and pick a copy of everything from the list above. For MinGW, just fire up the following to retrieve the source:
svn co https://mingw-w64.svn.sourceforge.net/svnroot/mingw-w64 mingw-w64
Another prerequisite that you shouldn't overlook is, since the compilation process is fraught with disappointments and restarts, the fastest and the more cores your CPU is/has, the better. Better try that process on the fastest Linux machine you can get your hands on first, and once you're satisfied that your compilation should work, do it on a slower machine if that's your final target.
For the record, I used a quad core Slackware 13.0 64 bit Linux server, which I'm hoping should be generic enough to have this guide apply to other Linux flavours.

File extraction and directory settings

If you haven't done so by now, you should extract all the tar archives downloaded above into your working directory. Now, a lot of guides will have you go through gmp+mpfr+mpc installation before you can fiddle with gcc, but that's really pointless. The newer gcc sources are designed to pick up and compile gmp, mpfr and mpc if they are available in the gcc source directory. Moreover, I have had trouble getting gcc 4.5.0 recognize the very new mpfr 3.0.0 when compiled as standalone, whereas it doesn't seem to have a problem picking it up from its source directory.
Therefore, here's what you should do once you have extracted everything:
mv mpfr-3.0.0/ gcc-4.5.0/mpfr
mv gmp-4.3.2/ gcc-4.5.0/gmp
mv mpc-0.8.2/ gcc-4.5.0/mpc
Once this is done, this is the content you should have in your working directory:
binutils-2.20.1/  binutils-2.20.1.tar.bz2  gcc-4.5.0/  gcc-4.5.0.tar.bz2  gmp-5.0.1.tar.bz2  mingw-w64/  mpc-0.8.2.tar.gz  mpfr-3.0.0.tar.bz2

Generalities

For most of the configuration, we will use the defaults, therefore, the binaries and includes will use /usr/local as their base (specific MinGW-w64 subdirectories will be created, don't worry). The only option I'm going to consistently add when running the versions configure is the --disable-nls to try to speed up things a little bit by disabling non Western language support.
Also, you should never compile any part of a cross compiler from within the extracted source directory. If you do, the whole process is bound to fail. Instead, we will create external build directories (eg. binutils-build) in our working space for each source we need to go through.
Also, since I am lucky enough to run on a quad core, I'm going to use the parallel processing option of make (-j) to considerably speed up the whole compilation process. The rule of thumb is to use j# with # being the number of cores you have at your disposal (altough I've also seen people doubling that number). Hence, almost every make command we call below will be affixed with -j4.
Oh yeah, and some people will advise to add a --build=<build-machine-triplet> all over the place, but most of the scripts we use are smart enough to detect cross compilation, so this is not necessary. You might see some warnings about --build not being specified, but you shouldn't worry too much about them.
Finally, gcc compilation is a bit unpredictable, especially if you use -j on make (but even without, weird things happen), so if your make process generates an error for any reason, the first thing to try is make again, to see if things get further. Even without -j, it sometimes takes 2 or 3 passes to get a specific section of the compilation working.

Binutils

And now the fun begins. Didn't encounter much of any issues with binutils, so the process goes as follows:
mkdir binutils-build; cd binutils-build
../binutils-2.20.1/configure --disable-nls --target=x86_64-w64-mingw32 --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32
make -j4
make install
In the above, the --target indicates that we ultimately want to produce a MinGW compiler that can produce x86_64 binaries (i.e. MinGW-w64), and the --enable-targets with 2 parameters is for multilib support, with 64 (x86_64) and 32 (i686) bit.The end result of all this is that you should get a bunch of x86_64-w64-mingw32 binaries into /usr/local/bin (ar, ld, etc)

MinGW headers

Pay attention here:  This is the headers install => the configure we run is NOT the one from trunk/ but the one from trunk/mingw-w64-headers/. If you try to run the configure from trunk/ at this stage, of course it will fail.
cd ..; mkdir mingw-build; cd mingw-build
../mingw-w64/trunk/mingw-w64-headers/configure --host=x86_64-w64-mingw32
make install
This should copy the MinGW headers into /usr/local/x86_64-w64-mingw32/include/.

MinGW directories and symlinks

With the above steps, you should end up with a /usr/local/x86_64-w64-mingw32/ directory that also contains a lib/ directory (which will be used for the 64 bit version of the libraries). If that's not the case you should create it. Now, for multilib, we'll also need a lib32/ directory, and some parts of MinGW expect a few specific directories, like lib64/ or /usr/local/mingw, so we create all that:
ln -s /usr/local/x86_64-w64-mingw32 /usr/local/mingw
mkdir -p /usr/local/x86_64-w64-mingw32/lib32
ln -s /usr/local/x86_64-w64-mingw32/lib /usr/local/x86_64-w64-mingw32/lib64

Gcc, pass 1

Now things start to get real (and problems start to appear if you don't use the right configure options):
cd ..; mkdir gcc-build; cd gcc-build
../gcc-4.5.0/configure --disable-nls --target=x86_64-w64-mingw32 --enable-languages=c,c++ --with-system-zlib --enable-multilib --enable-version-specific-runtime-libs --enable-shared --enable-fully-dynamic-string
OK, a little clarification about our configure options:
  • --enable-languages=c,c++, because, who the hell compiles 64 bit Windows binaries in Fortran or Ada, and your time is precious (plus, I think the Fortran/Ada source generate some errors). C and C++ are all you need.
  • --with-system-zlib, at least on Slackware, you do want to use that option to avoid an uncorrectable "Link tests are not allowed after GCC_NO_EXECUTABLES" error in the zlib/ directory provided by gcc. And I'm at loss to figure out why gcc does include the sources for zlib in their archive, but not the ones for gmp, mpc, mpfr, as it'd make life a lot easier for everybody.
  • --enable-version-specific-runtime-libs, --enable-fully-dynamic-string, because some people use these and say they are useful.
    [UPDATE: 2010.09.09] According to the MinGW-w64 developers, you should NOT use --enable-version-specific-runtime-libs, as this causes issues. There is currently a long discussion on the MinGW-w64 mailing list about this. Make sure you read it! I may update this guide at some stage
  • --enable-multilib, to have -m32 and -m64 support!
  • --enable-shared, to be able to compile DLLs as well as static libraries.
make all-gcc -j4
Yay, our first compilation error (sadly, won't be the last!). The above fails on
checking for gmp internal files... configure: error: header files gmp-impl.h and longlong.h not found
make: *** [configure-mpfr] Error 1
To fix that error:
cp ../gcc-4.5.0/gmp/gmp-impl.h gmp; cp ../gcc-4.5.0/gmp/longlong.h gmp
After that, the process should complete successfully with:
make all-gcc -j4
make install-gcc
Note that if you get other errors during the build (eg. "Link tests are not allowed after GCC_NO_EXECUTABLES"), just try without -j a couple of times to see if this is really a permanent error, or just gcc screwing with your nerves.

Crt (MinGW-w64)

Nothing fancy here. If you use the latest from svn, things should compile pretty nicely with:
cd ../mingw-build
../mingw-w64/trunk/configure --disable-nls --host=x86_64-w64-mingw32 --enable-lib32
make -j4
make install -j4
I think --enable-lib32 is superfluous, as recent MinGW-w64 seem to be hardwired for multilib by default. Just make sure that 32 and 64 bit are enabled on the configure summary screen.

Gcc, pass 2

"It's right when you start seeing the light at the end of the tunnel, that the arch collapses."

Thought you were out of the woods? Think again:
cd ../gcc-build
make -j4
will choke on:
/usr/local/x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/local/x86_64-w64-mingw32/lib/libmingw32.a when searching for -lmingw32
and a whole bunch of similar errors. Obviously, since we're in gcc-build/x86_64-w64-mingw32/32/libgcc/ when that happens, ld should be looking in lib32/ rather than lib/.
Now, there's probably a smarter approach, but the easiest way I found to fix this is to:
  1. edit <your_working_dir>/gcc-build/x86_64-w64-mingw32/32/libgcc/Makefile
  2. copy the CC line into a CC32 line and replace all the /lib by /lib32
  3. replace GCC_FOR_TARGET = $(CC) with GCC_FOR_TARGET = $(CC32)
Note that just editing the CC line doesn't work (which I guess is due to libtool use)! You need to create a new CC32 variable.
make -j4
You might get a "Link tests are not allowed after GCC_NO_EXECUTABLES" (what the heck does that error actually mean anyway?). If that happens, just retry... until it breaks again with the "skipping incompatible when searching for -lmingw32" error again in <your_working_dir>/gcc-build/x86_64-w64-mingw32/32/libssp/
Same trick as above applies, with editing the Makefile, only this time you can edit the CC and CPP variables directly and just replace /lib with /lib32 again.
make -j4
Yup, choked again, this time in <your_working_dir>/gcc-build/x86_64-w64-mingw32/libstdc++-v3/libsupc++/, with:
/bin/sh: ../libtool: No such file or directory
Easiest solution I found:
cp ./x86_64-w64-mingw32/libssp/libtool ./x86_64-w64-mingw32/libstdc++-v3
Then once more:
make -j4
Might get a few errors, that go away on retry, and then:
../../../../gcc-4.5.0/libstdc++-v3/src/atomic.cc:26:21: fatal error: gstdint.h: No such file or directory
Easy to fix:
ln -s /usr/local/mingw/include/stdint.h /usr/local/mingw/include/gstdint.h
make -j4
...and then again:
make[6]: Entering directory `/mnt/hd/src/clean/gcc-build/x86_64-w64-mingw32/32/libstdc++-v3'
make[6]: *** No rule to make target `all'.  Stop.
Well, no surprise: there's no makefile in <your_working_dir>/gcc-build/x86_64-w64-mingw32/32/libstdc++-v3/! How I fixed it?
rm -r x86_64-w64-mingw32/32/libstdc++-v3
ln -s x86_64-w64-mingw32/libstdc++-v3/32 x86_64-w64-mingw32/32/libstdc++-v3
make -j4
...and once more, plenty of errors in ./x86_64-w64-mingw32/32/libssp/ about lib vs lib32. At least we can't say gcc compilation isn't keeping us entertained. This time, we can edit ./x86_64-w64-mingw32/32/libssp/libtool and do a search for -m32. For each line that has -m32, just replace /lib with /lib32.
$ make -j4
YAY!!! Completion at last! Just one final thing to do:
make install -j4
If you managed to make it through that last ordeal, you should now have a fully working MinGW-w64 gcc compiler, capable of producing 32 and 64 bit windows binaries, as well as static or dynamic (DLL) libraries, and using nothing but the latest versions of all the tools. Pretty cool huh?
To compile, just remember to add a --host=x86_64-w64-mingw32 when running configure, and possibly export a CFLAGS=-m32 if you want to produce 32 bit binaries.

2010-06-14

error LNK2005: strncmp already defined in LIBCMT.lib(strncmp.obj)

You're trying to mix "Multi-threaded (/MT)" with "Multi-threaded DLL (/MD)". Enough said.

2010-06-07

Preventing USB devices with different serials to be seen as separate devices

Once again, I have to give props to Xiaofan:

The following is quoted from a USB-IF forum post (the link is now invalid)
http://www.usb.org/phpbb/viewtopic.php?p=33850

"Win2000/XP has a way to ignore the serial number.
This is copied form an AppNote I wrote:
-------------------------------------------------------
Ignore serial number in Win2000 / XP In Windows 2000 and XP,
there is a way to ignore the serial number for a certain device.
This is not recommended in general, but there are reasons to do so.

This is the registry key
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags]
The global way: The entry below does enable the serial numbers despite
its name! It is already there after a fresh installation.
GlobalDisableSerNumGen = 1
We recommend keeping the above setting unchanged.

Now here is the individual way. Create an entry under the
above ...\UsbFlags key. The name must start with "IgnoreHWSerNum"
followed by the vendor and product ID of the device. The value for the
entry is 1 for disable.
Example:
IgnoreHWSerNum0536016A= 1
Our vendor ID (VID) is 0536 (hex), the product ID (PID) depends
on the interface you choose.

2010-06-03

Showing hidden devices on Windows

Courtesy of the good people of the libusb-devel mailing list:
  1. Set a System (not user) environment variable called:
    DevMgr_Show_NonPresent_Devices with value 1
  2. Tell device mgr (thru menus) to show hidden devices
See http://www.ftdichip.com/Documents/AppNotes/AN_107_AdvancedDriverOptions_AN_000073.pdf

This trick seems to work fine on Windows 7 as well.

2010-05-24

Compiling resource files with Visual Studio Express

If you pick a Visual Studio project with an MFC GUI app, and try to compile it with Visual Studio Express, you should run into the error:
fatal error RC1050: Cannot open include file 'afxres.h'.
The solution? Replace your:
#include "afxres.h"
from your .rc file with the following:
#include <windows.h>
#define IDC_STATIC -1

2010-05-14

running XP inside qemu on Windows

  • Compiled qemu from source using MinGW32/Msys (hint: add the "target-list=i386-softmmu" so that you only compile the target of interest to you). Haven't figured out how to get a Ctrl-Alt-2 that actually works yet...
  • Installed UltraVNC
  • Copied the qemu exec from i386-softmmu to pc-bios and ran everything from pc-bios
  • Created HDD image (with qemu-img)
  • Default of qemu on IPV6 system is to use IPV6 which makes the VNC connection unavailable - need to provide IPv4 address to -vnc option, and thus, from the pc-bios directory:
    qemu -usb -vnc 127.0.0.1:0 -hda winxp.img -m 512 -localtime -net user -net nic,model=rtl8139  -cdrom //./d:
  • Connected through UltraVNC viewer with "localhost::5900" and installed XP
  • First thing to do once XP is installed is to disable mouse acceleration by disabling "Enhance Pointer Precision" in Mouse Properties -> Pointer Options

2010-04-20

unresolved external symbol CLSID_FileOpenDialog

error LNK2001: unresolved external symbol IID_IFileOpenDialog
error LNK2001: unresolved external symbol CLSID_FileOpenDialog
You're missing uuid.lib.

2010-04-06

Launching the device manager in one click

A few of us need to have quick access to the device manager always, and while things have improved on Windows 7, we're still not there with regards to one click access. The solution:
C:\Windows\system32\mmc.exe C:\Windows\system32\devmgmt.msc

2010-03-24

Windows UAC and bash's "Bad File Number" error

Today's problem: trying to run a freshly compiled setup_driver.exe from MSYS/MinGW produces the following:
sh: ./setup_driver.exe: Bad file number
The reason: Microsoft's implementation of UAC will try to give a free pass to any application that has "setup" in its name, and run it in elevated mode (after asking for confirmation).
This doesn't fare well with most shells running on Windows, as they don't know how to call the UAC elevation process, and you get the error above.

Rename your application to something that does not contain "setup" and your problem is gone.
Also applies to variations of "install" in your name.

Dynamically building headers with automake / autotools

Say part of your build process is meant to generate a custom include file, eg. resource.h, built from embedded resources and you want to ensure that this header is always built before the rest.

The trick then is to add
BUILT_SOURCES = resource.h
in your Makefile/Makefile.am as all files mentioned as BUILT_SOURCES will be built before any of the normal compilation rules run.

This is what we do in WDI (Windows Driver Installer) for libusb 1.0 with a Makefile.am that looks like:
BUILT_SOURCES = resource.h
lib_LTLIBRARIES = libusb-wdi.la

LIB_SRC = resource.h infs.h usbi.h installer.h installer_library.h installer_library.c

libusb_wdi_la_CFLAGS = $(VISIBILITY_CFLAGS) $(AM_CFLAGS) -L../../libusb/libusb/.libs -lusb-1.0 
libusb_wdi_la_SOURCES = $(LIB_SRC)

resource.h:
    ../embedder/embedder.exe resource.h

clean-local:
    -rm -rf resource.h

2010-03-18

Removing trailing whitespaces in Visual Studio

The following will remove trailing whitespaces whenever you save a file in Visual Studio 2008. Convenient!
  1. Go to Tools -> Macros -> Macro Explorer
  2. Double click "MyMacros -> Module1
  3. In the new Project Explorer Tree, double click on "EnvironmentEvents" above "Module1"
  4. After the #End Region for #Region "Automatically generated code, do not modify", add the following:
    Private saved As Boolean = False
        Private Sub DocumentEvents_DocumentSaved(ByVal document As EnvDTE.Document) _
                                                 Handles DocumentEvents.DocumentSaved
            If Not saved Then
                Try
                    ' Remove all the trailing whitespaces.
                    DTE.Find.FindReplace(vsFindAction.vsFindActionReplaceAll, _
                                         "{:Zs|\t}+$", _
                                         vsFindOptions.vsFindOptionsRegularExpression, _
                                         String.Empty, _
                                         vsFindTarget.vsFindTargetCurrentDocument, , , _
                                         vsFindResultsLocation.vsFindResultsNone)
    
                    saved = True
                    document.Save()
                Catch ex As Exception
                    MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Trim White Space exception")
                End Try
            Else
                saved = False
            End If
        End Sub

2010-03-08

A service installation section in this inf is invalid

If you've been banging your head against the wall on this error, and you are trying to install a 64 bit driver on Windows 7 x64 or Windows Vista x64, the problem might simply be due to the ServiceBinary property of your inf file referencing the 32 bit driver (.sys) rather than the 64 bit.

Make sure then that you have something like:
ServiceBinary = %12%\mydriver_x64.sys
and try again. Might work better this time around.

2010-01-26

ERROR: "usb_mon_register" [drivers/usb/mon/usbmon.ko] undefined!

If you are getting this kind error in Linux when recompiling a kernel module, it usually means that your kernel configuration and the actual configuration used to compile your last kernel are out of sync.

This usually gets resolved by recompiling your kernel, and then (if needed) by recompiling your modules again. Of course, you will need to be running the new kernel for the modules to work.