If GDI+ is not an option for you, then I would recommend to use one of the many libraries for converting image formats. For example this one:
That doesn't mean you should not have a look at the JPEG specification, as Harvey suggested in Solution 2. It just means that the JPEG standard is not trivial to understand implement and you might end up with a couple thousand line of C++ code. So for faster results you might want to use a good library.
A word about rotation. You can rotate a JPEG image by converting it into a bitmap, then rotate it (which is quite easy) and then re-encode it as a JPEG. This process is however not absolutely lossless, because JPEG is a lossy compression method. There is however a way of rotating a JPEG image without converting it into a bitmap, just by manipulating the internal data structures. Some libraries support lossles JPEG rotation. Just google for "jpegtran".