Click here to Skip to main content
15,917,177 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problems with malloc Pin
r3dqu33n5-Feb-05 1:38
r3dqu33n5-Feb-05 1:38 
GeneralRe: Problems with malloc Pin
WoutL5-Feb-05 1:54
WoutL5-Feb-05 1:54 
GeneralRe: Problems with malloc Pin
Anonymous5-Feb-05 3:57
Anonymous5-Feb-05 3:57 
GeneralRe: Problems with malloc Pin
Mike Dimmick5-Feb-05 1:57
Mike Dimmick5-Feb-05 1:57 
GeneralRe: Problems with malloc Pin
Michael Dunn5-Feb-05 20:49
sitebuilderMichael Dunn5-Feb-05 20:49 
GeneralHTTP chunked encoding Pin
Taka Muraoka4-Feb-05 23:47
Taka Muraoka4-Feb-05 23:47 
GeneralA Problem with PostgreSQl Pin
tranglt4-Feb-05 22:44
tranglt4-Feb-05 22:44 
GeneralGDI+ Bitmaps Pin
jgeorge214-Feb-05 22:04
jgeorge214-Feb-05 22:04 
In my quest for a simple to use image loading library I came across GDI+. I only want to use the portion of GDI+ that loads images, since it loads every image type that I would ever need into a DIB (which I can extract and feed OpenGL). However, I have the most annoying and frustrating issue: the image is not loaded and the lastResult member of the Bitmap object indicates InvalidParameter. Obviously I'm feeding it something bad. The relevant code snippet follows:

<br />
xBoolean xImage::Load (char *fileName, xBoolean mipmap)<br />
{<br />
	BitmapData	*bmpData = new BitmapData ();<br />
	Rect		*rect = new Rect ();<br />
	sint32		format, stride;<br />
	uint32		i, j;<br />
	xbyte		*tempBuffer;<br />
	uint32		wideLen;<br />
	WCHAR		*fileNameW = NULL;<br />
<br />
	if (fileName == NULL)						// Early out if string is NULL<br />
	return xfalse;<br />
<br />
	// Convert C string to UNICODE<br />
	wideLen = MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, fileName, -1, NULL, 0);		// Get necessary length<br />
	fileNameW = (WCHAR *)malloc (wideLen);							// Alloc string<br />
	MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, fileName, -1, fileNameW, wideLen);		// Translate string<br />
<br />
	Bitmap		bmp ((const WCHAR *)fileNameW, FALSE);<br />
<br />
	...<br />


The string fileName is being properly translated to fileNameW as below:

<br />
// Original String<br />
	fileName[0]	119 'w'	char<br />
	fileName[1]	104 'h'	char<br />
	fileName[2]	105 'i'	char<br />
	fileName[3]	116 't'	char<br />
	fileName[4]	101 'e'	char<br />
	fileName[5]	46 '.'	char<br />
	fileName[6]	116 't'	char<br />
	fileName[7]	103 'g'	char<br />
	fileName[8]	97 'a'	char<br />
	fileName[9]	0	char<br />
<br />
// Wide String<br />
	fileNameW[0]	119	unsigned short<br />
	fileNameW[1]	104	unsigned short<br />
	fileNameW[2]	105	unsigned short<br />
	fileNameW[3]	116	unsigned short<br />
	fileNameW[4]	101	unsigned short<br />
	fileNameW[5]	46	unsigned short<br />
	fileNameW[6]	116	unsigned short<br />
	fileNameW[7]	103	unsigned short<br />
	fileNameW[8]	97	unsigned short<br />
	fileNameW[9]	0	unsigned short<br />


The constructor for the Bitmap object is as follows:

<br />
class Bitmap : public Image<br />
{<br />
public:<br />
    friend class Image;<br />
    friend class CachedBitmap;<br />
<br />
    Bitmap(<br />
        IN const WCHAR *filename,<br />
        IN BOOL useEmbeddedColorManagement = FALSE<br />
    );<br />


Recall that the lastResult member is being set to InvalidParameter. Here are the possible GDI+ return values:

<br />
enum Status<br />
{<br />
    Ok = 0,<br />
    GenericError = 1,<br />
    InvalidParameter = 2,<br />
    OutOfMemory = 3,<br />
    ObjectBusy = 4,<br />
    InsufficientBuffer = 5,<br />
    NotImplemented = 6,<br />
    Win32Error = 7,<br />
    WrongState = 8,<br />
    Aborted = 9,<br />
    FileNotFound = 10,<br />
    ValueOverflow = 11,<br />
    AccessDenied = 12,<br />
    UnknownImageFormat = 13,<br />
    FontFamilyNotFound = 14,<br />
    FontStyleNotFound = 15,<br />
    NotTrueTypeFont = 16,<br />
    UnsupportedGdiplusVersion = 17,<br />
    GdiplusNotInitialized = 18,<br />
    PropertyNotFound = 19,<br />
    PropertyNotSupported = 20<br />
};<br />


It isn't that it can't find the file, GDI+ is initialized properly, and it isn't any useful error. One other thing, if I change the line

<br />
Bitmap		bmp ((const WCHAR *)fileNameW, FALSE);<br />


to read

<br />
Bitmap		*bmp = new Bitmap ((const WCHAR *)fileNameW, FALSE);<br />


the compiler spits an error about not finding the constructor, which I found odd. If anyone can help, it would be much appreciated.
GeneralRe: GDI+ Bitmaps Pin
PJ Arends5-Feb-05 8:57
professionalPJ Arends5-Feb-05 8:57 
Generalarchiving code or binary within my prog Pin
Spiritofamerica4-Feb-05 20:25
Spiritofamerica4-Feb-05 20:25 
GeneralRe: archiving code or binary within my prog Pin
jgeorge214-Feb-05 22:11
jgeorge214-Feb-05 22:11 
GeneralRe: archiving code or binary within my prog Pin
Maximilien5-Feb-05 3:41
Maximilien5-Feb-05 3:41 
GeneralRe: archiving code or binary within my prog Pin
Chris Losinger5-Feb-05 3:44
professionalChris Losinger5-Feb-05 3:44 
Generalcreate thread in run time Pin
javad_20054-Feb-05 20:23
javad_20054-Feb-05 20:23 
GeneralRe: create thread in run time Pin
2249174-Feb-05 21:00
2249174-Feb-05 21:00 
GeneralXML Parsing in VC++ Pin
cj_rahul4-Feb-05 19:55
cj_rahul4-Feb-05 19:55 
GeneralRe: XML Parsing in VC++ Pin
ThatsAlok4-Feb-05 22:02
ThatsAlok4-Feb-05 22:02 
GeneralRe: XML Parsing in VC++ Pin
ThatsAlok5-Feb-05 0:31
ThatsAlok5-Feb-05 0:31 
Generalplz guide me in ids Pin
miss smriti4-Feb-05 19:02
miss smriti4-Feb-05 19:02 
GeneralRe: plz guide me in ids Pin
Maximilien4-Feb-05 19:28
Maximilien4-Feb-05 19:28 
GeneralRe: plz guide me in ids Pin
miss smriti4-Feb-05 23:22
miss smriti4-Feb-05 23:22 
GeneralRe: plz guide me in ids Pin
Maximilien5-Feb-05 3:38
Maximilien5-Feb-05 3:38 
GeneralRe: plz guide me in ids Pin
2249174-Feb-05 19:38
2249174-Feb-05 19:38 
GeneralRe: plz guide me in ids Pin
miss smriti4-Feb-05 23:20
miss smriti4-Feb-05 23:20 
GeneralRe: plz guide me in ids Pin
ThatsAlok4-Feb-05 22:04
ThatsAlok4-Feb-05 22:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.