Skip navigation

Well I got it to build pretty easily. but it didn’t work as a dll for me AT ALL.

First I tried the easy way and got the prebuilt binaries. But I kept getting this error:

Unhandled exception at 0x7d64d233 in Using_libpng.exe: 0xC0000005: Access violation writing location 0x00000014.

which is discussed here (but no answer is found.. he just ends up saying “it works for me!”) and an apparent answer is given here

The answer (from the second thread posting) that I believe it to be a correct synopsis of the root cause was:

So you pass the FILE* from fopen to png_init_io which will cause libpng
itself to make fread() calls on that FILE*. If libpng then crashes in
png_read_info it means that the library you used to allocate the FILE* (i.e.
the one containing the implementation of fopen which was called in (1)) is
*not* the same as the library libpng expects to call to read from the FILE*
(i.e. the library was compiled/linked against to get the
implementation of fread).

If you can”t change your library to match libpng and you don”t want to
compile and build libpng (statically) to change it then you have no choice
but to implement your own file IO and hope that there are no other issues (I
believe that file IO with stdio is the *only* case where an object is
allocated in the application and subject to library calls within libpng.)

basically he’s saying that libpng was built using a “different version” of file reading capability than what you have on your machine.

Probably true because i’m running the accursed x64 edition of winxp pro.

so i set out to compile my own libpng

Finally got it into a

visual studio 2008 project file

(which you can download! see I am nice!), this may help you if you can’t get it to work still.

So I built it as a big hunking .lib file (800k!) and it works now. So fuck it, I don’t care how big it is, it works, and I don’t have to worry about dll’s.

This is a nice library now, once I can get it to build.

Treating windows developers badly is not cool, btw, png team.


    • nireq
    • Posted April 28, 2009 at 12:26 pm
    • Permalink

    thanks for good solution to this nasty problem

    • suffering developer
    • Posted November 24, 2009 at 8:15 pm
    • Permalink

    you are my hero

  1. good one dude.. :)

    • Nix
    • Posted December 22, 2009 at 12:40 pm
    • Permalink

    Awesome, this helped a lot.

    • daniel
    • Posted April 17, 2010 at 5:48 am
    • Permalink

    I was trying to build something using libpng for windows and I downloaded your visual studio project and it worked. Thanks a lot dude

    • Anonymous
    • Posted August 13, 2011 at 11:44 am
    • Permalink

    this helps me! Thanks a lot.

    • Anonymous
    • Posted November 22, 2011 at 4:42 am
    • Permalink

    thanks this fixed me issue!

    • Anonymous
    • Posted January 30, 2012 at 2:33 pm
    • Permalink

    You’re GOD!

    • planty182
    • Posted April 6, 2012 at 4:36 pm
    • Permalink

    your account for the download has been suspended *cries*

    I’ve got the exact same problem, if you cant put up a downloadable file that will compile the libpng files for me, then could you give me a rough guide on how to do it myself? I’m running Vis stud 2010 :)

    Please help! I’ve only got a month to finish this project, and don’t really have time to remake it all on a linux enviroment :/

    Hope you can get back to me!


    • comradepp
    • Posted November 14, 2012 at 2:33 pm
    • Permalink

    There is simpler solution: you can just redefine read function.
    Use png_set_read_fn(*pngStructPtr, file, ReadFileFunc), where
    ReadFileFunc(png_structp pngStructPtr, png_bytep data, png_size_t length) {
    FILE *file = (FILE *)png_get_io_ptr(pngStructPtr);
    fread(data, sizeof(png_byte), length, file);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: