http://www.libgd.org/FAQ#Why_does_bgd.dll_crash_with_my_C_program.3F -------------------------------------------------- Why does bgd.dll crash with my C program?
You are trying to use gd's stdio library functions with a different C runtime library. Read on for notes on individual compilers.
Microsoft Visual C++: If you want to use gdImageCreateFromPng, gdImagePng, and other functions that take a FILE *, you MUST use Visual C++ 6.0 or earlier and you MUST link with the "multithreaded DLL" runtime library option. If you wish to use the .NET compiler, read the "Borland C++" section for an alternative method.
If you do not take the time to understand this, your program simply will not work! Note: the "multithreaded debug DLL" option is NOT the same thing and will NOT work. If you don't want to use the "multithreaded DLL" runtime library option (see "code generation" under "settings"), then read the "Borland C++" section for an alternative method.
GNU mingw32: you should have no problems. The mingw32 compiler is designed to link your application with msvcrt.dll, the same C runtime library that bgd.dll was linked with. (We build it with mingw32, as it happens.)
GNU cygwin: if you are compiling with -mno-cygwin, see the GNU mingw32 entry, above. If you are linking with the full cygwin runtime library, you might be better off installing gd from source. "configure" and "make install" should work for you as they do on full Unix systems. If you have solved the problem of using a win32 DLL from cygwin, however, you can certainly use bgd.dll using the same techniques described below for Borland C++.
Borland C++: this product apparently provides its own C runtime library, incompatible with Microsoft's msvcrt.dll. You cannot use the FILE * functions in gd.h. However, there is an alternative. The gdImagePngPtr and gdImageCreateFromPngPtr functions provide a way to write image file data to a memory buffer, or load an image from a buffer of image file data. See the next two questions for code samples. How do I load an image file from a buffer in memory? The following C code shows how to load an entire image file into a buffer in memory, then ask gd to read the image from that buffer. Please note that since you are responsible for allocating the buffer, You are also responsible for freeing the buffer with your normal memory management functions.
Note to Borland C++ programmers: this code will allow you to load an image using the bgd.dll library, because no FILE * objects are passed across the DLL boundary.
Of course, there is a gdImageCreateFromJpegPtr function available as well. This particular example loads a PNG image.