Setting Up PNGWriter for Microsoft Visual C++ .NET on Windows XP

by Dr John Charlery

 

This document is a short HowTo about using PNGwriter with the Microsoft Visual C++ .NET compiler, and is one way to use PNGwriter under Windows.

 

Please note: This document was written with a specific version of PNGwriter in mind, but you should always try to use the latest version of PNGwriter, available from the PNGwriter Website. You should also attempt to use the latest versions of zlib and libpng.

 

Please note: A few versions lower than 0.4.6 won't compile without modification on this compiler (and Borland Builder, and perhaps other Windows compilers), so be sure to have at least version 0.4.6.

 

Please note: pngwriter.cc has to be renamed to pngwiter.cpp for MSVC7. If the extension is not changed then the C/C++ folder for the project property does not become visible and hence the MSVC7's default of using compiled headers in its project build will always return an error about being unable to find some precompiled header. It is necessary to change that feature in the project property in order to successfully build the PNGwriter library using this compiler.

 

Setting Up ZLIB and LibPNG

 

1.    Download the latest zlib 1.2.1 zip file and extract the files into the folder c:\zlib.

 

2.    Download the libpng 1.2.5 zip file and extract the files into the folder C:\lpng125.

 

3.    Download the freetype-2.1.8.exe file and install the file. The default folder for installation is “C:\freetype”. The exact folder you use for the installation is not important, but you need to remember where the files are installed.

 

4.    Open Microsoft Visual C++ .NET

 

4.    Select File ==> Open Project

 

5.    Go to the directory “C:\libpng125\Projects\MSVC” and select the file “libpng.dswand click “Open”. A message box asking whether to convert and open the project will be displayed. Select “Yes to All.

 

6.    If the Solution Explorer is not visible, Select View==>Solution Explorer

7.    In the Solution Explorer window, cascade “zlib, then cascade “Source Files”. Delete “infblock.c”, “infcodes.c” and “infutil.c”. (These files are not provided with zlib ver 1.2.1).

 

8.    From Build (in the menu bar) select Configuration Manager...

a.    Change “Active Solution Configuration” to “LIB

b.    Make sure Platform is “WIN32

c.     Place ticks for both libpng and zlib projects in Build column.

d.    Click close.

 

9.    From Build (in the menu bar) select “Clean Solution

10. From Build (in the menu bar again) select “Rebuild Solution”.

You may a few warnings messages, but as long as there is no error detected, it will be okay.

 

11. A number of files will then be created.

12. Go to the directory “C:\lpng125\projects\MSVC\Win32\libpng\lib” and copy the file “libpng.lib” to your Visual C++ “lib” directory. (if you used the normal installation for MSCV.NET, the lib directory will be at “C:\Program files\Microsoft Visual Studio .NET 2003\VC7

13. Go to the directory “C:\lpng125\projects\MSVC\Win32\zlib\lib” and copy the file “zlib.lib” to your Visual C++ “lib” directory.

 

14. Create a new directory and copy all the obj (*.obj) files from “C:\lpng125\projects\MSVC\Win32\libpng\lib” and “C:\lpng125\projects\MSVC\Win32\zlib\lib” into it. (This is just for convenience).

15. Go to the directory where you installed FREETYPE. If you used the default, it will be at “C:\freetype”.

(i)             From the bin folder of freetype, copy the files freetype6.dll and zlib1.dll to the bin folder of MSVC7 (the default path is “C:\Program files\Microsoft Visual Studio .NET 2003\VC7\BIN”)

(ii)           From the lib folder of freetype, copy the files libfreetype.lib to the lib folder of MSVC7 (the default path is “C:\Program files\Microsoft Visual Studio .NET 2003\VC7\LIB”)

(iii)          From the include folder of freetype, copy the file ft2build.h to the include folder of MSVC7.

(iv)          From the include\freetype2 folder of freetype, copy the entire folder freetype (including folder’s name) to the include folder of MSVC7. Retain the freetype folder’s name in MSVC7 (i.e. freetype becomes a sub-folder of MSVC7’s include folder.

 

(v)            Check to see if the file unistd.h is included in the “include folder of MSVC7. If it isn’t, you need to locate a copy and insert it into MSVC7’s include folder. This file can be found with any GCC compiler program and is readily available on the internet.

 

 

 

Setting Up PNGWriter

 

1.    Download and extract the PNGWriter-0.4.6 files to your C:\ drive. (Retain the directory structure of the zipped file).

 

2.    From the “SRC” folder of where PNGWriter-0.4.6 was extracted, copy the files “pngwriter.cc” and “pngwriter.h” to the folder where you copied the zlib and libpng obj files. Rename the file pngwriter.cc to pngwriter.cpp. (This is in order to access the C\C++ folder in MSVC7’s project properties.

3.    From C:\libpng125, copy the files png.h and pngconf.h to MSVC7’s include folder and from the C:\zlib folder, copy the files zlib.h, zconf.h to the include folder of MSVC7.

 

3.    Close all projects in MS Visual C++.

 

4.    Select File ==> New Project==> Win32 Console Project.

(a)           Type “pngwriter” (without the quotes) in the Name window. For Location, browse to the folder where the zlib and libpng obj files were copied to.

(b)           Click OK and then Finish.

 

5.    If the Solution Explorer is not visible, Select View ==> Solution Explorer

6.    In the Solution Explorer Window, cascade “pngwriter”.

(a)           Under “Source Files”, remove “pngwriter.cpp”

(b)           Right click on “Source Files” and select Add ==> Add Existing Item…”, select pngwriter.cpp and click open.

(c)           Right click “Header Files” and select Add ==> Add Existing Item…”, select pngwriter.h and click open.

(d)           Remove the files stdafx.cpp and stdafx.h from the Solution Explorer.

(e)           Right click “pngwriter” (top of list) and select Add ==> Add Existing Item…, select the file libpng.lib from MSVC7’s lib folder, then click open.

(f)             Right click “pngwriter” (top of list) and select Add ==> Add Existing Item…, select the file libfreetype.lib from MSVC7’s lib folder, then click open.

 

7.    Select Project ==> pngwriter Properties…

(a)           Click on “General”. For “Configuration Type”, replace “Application (.exe)” withStatic Library (.LIB)

(b)           Click on C/C++, then Precompiled Headers, select Not Using Precompiled Headersfor Create/Use Precompiled Headers

(c)           Click Apply and then OK.

 

8.    Save the Project

9.    Select Build ==> Clean pngwriter

10. Select Build ==> Build pngwriter

(a)           The file “pngwriter.lib” will be created and stored in the folder called “Debug” - a a sub-folder of where you copied the obj files. You may now copy pngwriter.lib to your Visual C++ “lib” folder. You may find it convenient to copy “pngwriter.cpp” and “pngwriter.h” to your Visual C++ “include” directory as well.

 

 

YOU ARE NOW READY TO GO.

 

 

Using PNGWriter

 

1.    Create your project in the normal way in Visual C++.

 

2.    Then select Project ==> Add Existing Item… and add the file pngwriter.lib to your project.

 

3.    If you copied the files “pngwriter.cpp” and “pngwriter.hto the Include folder of MSVC7, then simply use the statement:

# include <pngwriter.cpp>

in your program code. Otherwise, include the path where pngwriter.cpp” and pngwriter.h” are to be found.

 

You can now build and compile in the usual way.