This code crashes on gdImageGifAnimBegin

Code:
#include <gd.h>
#include <string.h>

int main(int argc, CHAR ** argv)
{

    gdImagePtr im = gdImageCreate(100, 100);
    FILE * out = fopen("anim.gif", "wb");

    if(out)
    {
        gdImageGifAnimBegin(im, out, 1, -1);
        gdImageGifAnimEnd(out);
        fclose(out);
    }

    gdImageDestroy(im);
    return 0;
}
Unhandled exception at 0x7c918fea (ntdll.dll) in Stupid.exe: 0xC0000005: Access violation writing location 0x00000010.

ntdll.dll!_RtlpWaitForCriticalSection@4() + 0x5b bytes
ntdll.dll!_RtlEnterCriticalSection@4() + 0x46 bytes
msvcrt.dll!__lock_file() + 0x33 bytes
msvcrt.dll!_fwrite() + 0x14 bytes
bgd.dll!1000c39a()

I can't understand why it is failing on this section. I am using Microsoft Visual Studio 8, and the bgd DLL is compiled with VC6 under multithreaded mode

Is it the difference in the compilation mode?