It looks like you're taking input that's meant to be RGB and treating it as RGBA (32-bit bitmap instead of 24-bit).
One of the most common causes of the left image is a buffer that is not properly aligned.
I believe Windows expects a DWORD aligned buffer.
One issue I see with the above code is that you do not want to use winRowSize to copy the actual pixels, you want to use a variable with the (width of the image * bytes per pixel). winRowSize copies the DWORD aligned size which is probably too big (although some images may work as they fall on DWORD alignment by default.)
Change the for loop:
for(i = 0; i < (width of the image * bytes per pixel); i++){
rawImage[location++] = row_pointer[i];
}
(You may also have to adjust the rgb to bgr code.)
Maybe you forgot to pad each row of pixels to occupy an integral number of DWORDs.
maybe the problem jpeg is not is rgb, but is cmyk instead (or even grayscale). not all jpegs are rgb.
PS, (yes I know jpegs are not actually rgb - are yuv instead, just trying to keep this answer simple)