Tuesday, June 19, 2007

Join to the xHarbour users list

Today I found an interesting new link in xHarbour.org Open Source official web page: the brand new xHarbour Users list.

If you wish to join, leave your data in:

xHarbour.org users list

Only basic data is taken, and it's not shown in the panel list, so you can be confident about the spam stuff.

Wednesday, June 13, 2007

Changing the resource compiler.

This article has been modified from its original spanish version. All references to other programming tools different of Xailer have been removed.

When working with Xailer, you probably have used the resource manager included in the IDE to handle the ImageList, Bitmaps, Icons, Cursors, etc.

Talking about resources, means that many of our visual appearance will be stored inside the own EXE file, this is a right and professional way to work because in other programming tools, all the visual interface came stored into a DLL.

In Xailer, all the resources are stored into a .RC file, which is created using the resource manager included in the IDE, this resource manager only handle the names of the resources, but doesn't let you "edit" them, (you will need an external tool), and then, during the application building process these resources are "compiled" and then linked into the final EXE file.

.RC files are like source code, in fact a .RC files is a text file, and, just the way we do with other source code, these .RC file must be compiled, the result of the compilation of a .RC file is a .RES file, equivalent to a .OBJ file in other programming languages, this .RES file will be linked into the .EXE as any other .OBJ file so the linker does this final step.

Since Xailer uses the Borland C++ 5.5, it comes with a "resource compiler" included, the name of the file is BRC32.EXE, in the \bin directory of the Borland C++ installation, the Xailer's building process uses this compiler to become the .RC files into .RES files, to let the ILINK32.EXE (also a Borland C++ component) do the rest of the job generating the final EXE.

The problem here is that BRC32.EXE in not a good choice when having huge resource files, or such .RC files are using big image files or have bitmaps with millions of colours, when this happens, the BRC32.EXE simply cannot compile the .RC file.

How to solve this problem ?

Easy, just change the resource compiler, obvious, but....

What resource compiler should I use ?

During my last trip to Spain in May 2007, I was talking with Bingen about this and he suggested me to use the Pelles C resource compiler, this is a free C compiler and its resource compiler works great with huge .RC files and with complex bitmaps that cannot be handled by the Borland C++ resource compiler.

The name of the resource compiler of Pelles C is PORC.EXE, it comes along with a PORC.DLL needed in order to compile our resurces, it works exactly the same way of the BRC32.EXE, so you don't need to change anything in the way you currently work, but the name of the compiler, instead of using the BRC32.EXE you will use the PORC.EXE and you are done, since the PORC uses the same compilation switches you don't need to change anything else.

Where to get it ?, dowload it from Pelles C download center, I do suggest to download the ZIP file, go to the second section of the page, where says Executables and Help. The zip is the suggested format because we don't need the full Pelles Installation, just the resource compiler. Using WinZip, WinRar search into the ZIP file and look for these two files :PORC.EXE & PORC.DLL, extract them in any directory in your hard drive.

To use them with Xailer, the fastest and easy way:

1) Copy the PORC.EXE and PORC.DLL into the \Xailer\bin directory
2) Open the Xailer's IDE, select Tools / Options... and you will see this form, select into the tree structure Resource Compiler into Directories section:



Select Use this compiler, set the path where PORC.EXE is (in my case \Xailer\bin) and that's all, it's no needed to touch the compilation flags, since they are the same for PORC and for BRC32.

4) From the Xailer's IDE open your project, and now BUILD (Alt+F9) the project, in order to recompile the resource file, is everything is ok, you will get a new EXE file without any problem.

During my test with Xailer, I faced a little problem, PORC was not generating the .RES file (the error the IDE will show is "cannot open FILE.RES", but the error will be shown until linking time), what was the cause ?, well, I have been working with Xailer since early versions, and in those early versions, the resource manager used to add a comment header at the top of the .RC file, this comment header had ";" as the comment indicator, which is not recognized by PORC as a valid comment operator, so, when it tried to compile, a syntax error occured, unfortunately, this error is not shown in the Xailer's compiling window, so you cannot trap it at the first time, after a little research the simply solution was to edit the old .RC file, change the ";" by the typical /*...*/ and all solved all my resources were compiled as expected.

Using this simply technical trick you will have a free yet powerful resource compiler and you will be able to handle bitmaps of any size or amount of colours.