First of all I learnt how to do this from

AVIStreamGetFrameOpen is always returning NULL. I checked to see if I could open the AVI file in windows media player and that worked, so that means it can't be a codec problem, right? I'm not too sure. All the variables have valid values before the call to AVIStreamGetFrameOpen

Here's my code:

if (AVIStreamOpenFromFile(&avi, file, streamtypeVIDEO, 0, OF_READ, NULL) != 0)

AVIStreamInfo (avi, &info, sizeof(info));
w = info.rcFrame.right - info.rcFrame.left;
h = info.rcFrame.bottom -;
lastframe = AVIStreamLength (avi);
mpf = AVIStreamSampleToTime (avi, lastframe) / lastframe;

header.biSize = sizeof (BITMAPINFOHEADER);                  
header.biPlanes = 1;                                        
header.biBitCount = 24;                                     
header.biWidth = w;                                     
header.biHeight = h;                                        
header.biCompression = BI_RGB;                              

bitmap = CreateDIBSection (hdc, (BITMAPINFO*)(&header), DIB_RGB_COLORS, (void**)(&data), NULL, NULL);
SelectObject (hdc, bitmap);

pgf = AVIStreamGetFrameOpen (avi, NULL);
if (!pgf)

If it matters, I'm using Windows 7 x64 and compiling with VC++ 2010. I have called AVIFileInit before this