Monday, December 31, 2007

Programming Tips: Filenames in GDI+

When using Bitmap class of GDI+ in Visual Studio 2005 and unicode names there is a problem when we try to load an image file which's name was acquired by a function of Windows API. While classic API returns paths in form: c:\some_folder\some_other_folder\filename , the Bitmap class constructor treats \ (backslash) as an escape character that means it is not treating it as a character but as an instruction to consider the next symbol as standard character (like & in HTML). In order for Bitmap constructor to see the file the path must be modified so that every backslash in the original path is followed by one more backslash. ie c:\\some_folder\\some_other_folder\\filename.

Friday, December 28, 2007

Programming Tips: GDI+ in Visual Studio 2005

This is the first mini article of a series where I present tips to solve programming problems that I have faced and have solved either by help from internet resources or research by my own.
An interesting problem that I face a while ago in Visual Studio 2005 was that while using a project with a precompiled header and classes and methods of GDI+ appeared to be hundreds of errors concerning everything that was related to GDI+ and even in header files of the GDI+ library (which was quite unlikely). After searching about the subject in a forum I found that in the precompiled header (stdafx.h) there is a line #define WIN32_LEAN_AND_MEAN which excludes unnecessairy declarations. As it seems it excludes the GDI+ declarations too and that way we cannot use it. Either by deleting this line or by commenting it out the problem is solved.