GEOPACK C/C++ Wrapper
I found the GEOPACK code by N. A. Tsyganenko to be by far the best and simplest code to calculate the Geomagnetic Field., but it is presented only as a single FORTRAN file, and I program mostly in C++. (Note - This is specifically a wrapper around the GEOPACK 2003 version, which includes IGRF field model in geocentric coordinates.
This is a header which wraps the RECALC and IGRF_GEO routines from GEOPACK.
acme_magfield.h
acme_magfield.cpp
Here are a couple of functions which provide the Magnetic Field as a Vector3D (my 3D vector class) for a given (X,Y,Z) geocentric cartesian position. Also can calculate the transverse magnetic field for given position and velocity vectors.
InitMagField() must be called during program startup to initialize the GEOPACK routines (using the current date - although you should be aware that the geomagnetic field changes slowly in time and that is availaible from GEOPACK).