GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Sep-2008, 06:37
Dominic Dominic is offline
Member
 
Join Date: Aug 2005
Posts: 123
Dominic will become famous soon enough

Not enough storage is available to process this command ... problem


Problems loading a large bit map

In my software I have a need to load a large bit map (70 Mbytes). I use ::LoadImage() to do this and load the bit map onto a Bitmap CStatic on a dialog.

After about 10 or 20 times of running my program, I get a failure being reported by ::LoadImage() which is
"Not enough storage is available to process this command"

If I reboot the computer, then all is well for another 10 or 20 times I run the software.

Clearly my software is not freeing up the temporary storage space for the bit map loading, but I am unsure how to resolve this.

No memory leakage is being reported in debug mode for Visual C++ studio v6.0, and there appears to be plenty of RAM available each time I run the program, which is then returned to the same value after the program has ended.

I am not sure what FreeLocal(p) is trying to do here. I was hoping it was freeing the 70 Mbytes of temp storage.

Does anyone know what might be going wrong?


For reference this is the code I am using :
CPP / C++ / C Code:


// FileName is the full character string for a file on the system which is the bit map file

	///////////////////////////////////////////////////////////////////////
	//
	//	Get the image from the file 
	//
	//////////////////////////////////////////////////////////////////////

	static void *p  = ::LoadImage(
				NULL,			// handle to instance
				FileName,			// Button Picture
				IMAGE_BITMAP,		// image type
				0,			// desired width
				0,			// desired height
				LR_DEFAULTCOLOR | LR_LOADFROMFILE   // load options
				);



	///////////////////////////////////////////////////////////////////////
	//
	//	Determine the error mesage if there was one 
	//
	//////////////////////////////////////////////////////////////////////




	if (!p){
		CString ErrorMessage;
		LPVOID lpMsgBuf;
		::FormatMessage( 
				FORMAT_MESSAGE_ALLOCATE_BUFFER | 
				FORMAT_MESSAGE_FROM_SYSTEM | 
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL,
				::GetLastError(),
				0, // Default language
				(LPTSTR) &lpMsgBuf,
				0,
				NULL 
				);
		CString Err;
		Err	= "CA330_200Dlg::LoadPicture\n";
		Err	+= FileName;
		Err	+= "\n";
		Err	+= (LPCTSTR)lpMsgBuf;
		CopyString(InitErrorMessage,Err.GetBuffer(0),sizeof(InitErrorMessage));
		LocalFree( lpMsgBuf );

		return false;


	}


	///////////////////////////////////////////////////////////////////////
	//
	//	Initialise a bit map handle, load a bitmap with it and select it
	//	into the compatible context device. 
	//
	//////////////////////////////////////////////////////////////////////


	MainPictureHandle	= static_cast <HBITMAP> (p);
	CBitmap	*pBm = CBitmap::FromHandle(MainPictureHandle);
	CBitmap *pOldBitmap = MainDisplayPicture.SelectObject(pBm);

	//	CDC	MainDisplayPicture; declared in an include file for the class 	

	LocalFree(p);
  #2  
Old 04-Sep-2008, 08:08
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 761
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Not enough storage is available to process this command ... problem


My help files suggest using DeleteObject() to release its associated memory.
  #3  
Old 05-Sep-2008, 03:05
Dominic Dominic is offline
Member
 
Join Date: Aug 2005
Posts: 123
Dominic will become famous soon enough

Re: Not enough storage is available to process this command ... problem


Thanks for the info.

I think (could be wrong) that DeleteObject() is a member of CDC, but ::LoadImage() is using some local storage that I dont have access to, other than a void pointer (p).

p is pointing to that storage space, but I am not sure it is a CDC object.

I cast the void pointer p, into MainPictureHandle which is a HBITMAP. Is there something I can do with this?

I belive that the CDC MainDisplayPicture is automatically deleted when the window is detroyed. I could be wrong, and may be this is the problem.
  #4  
Old 05-Sep-2008, 06:00
Dominic Dominic is offline
Member
 
Join Date: Aug 2005
Posts: 123
Dominic will become famous soon enough

Re: Not enough storage is available to process this command ... problem


A further update:

Firstly I was wrong about DeleteObject, I have now used it as
CPP / C++ / C Code:
::DeleteObject(p);

where p is pointing the void memory space allocated by ::LoadImage();

I just hope that DeleteObject() knows how much of "p" to delete.


It compiles.
It runs.
It closes down with out error
but time will tell as they say.

Thanks for the help, lets see what happens.
  #5  
Old 08-Sep-2008, 20:14
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: Not enough storage is available to process this command ... problem


Given MSDN suggests destroying with DeleteObject (here), I would assume it's doing what it's supposed to. It's the way malloc and free, new and delete, work. You don't specify the size when you free/delete the memory used, but it knows what to do with it.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How a child process past a value to parent process? Reny Computer Software Forum - Linux 11 09-Apr-2007 08:46
How to return value from child process to parent process Reny C Programming Language 1 16-Mar-2007 10:38
Program on creating a process!! sac_garg C Programming Language 3 01-Oct-2006 09:22
round robin scheduling using c eclipt C Programming Language 1 27-Dec-2005 16:34
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:52.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.