Click here to Skip to main content
16,011,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Focus Rect on a CButton Pin
Derek Lakin12-Sep-01 22:13
Derek Lakin12-Sep-01 22:13 
GeneralRe: Focus Rect on a CButton Pin
Remi Morin13-Sep-01 3:50
Remi Morin13-Sep-01 3:50 
General_T("") Pin
RobJones12-Sep-01 9:52
RobJones12-Sep-01 9:52 
GeneralRe: _T("") Pin
Chris Losinger12-Sep-01 9:56
professionalChris Losinger12-Sep-01 9:56 
GeneralAppending integer values to a string? (for Tree labels) Pin
12-Sep-01 9:12
suss12-Sep-01 9:12 
GeneralRe: Appending integer values to a string? (for Tree labels) Pin
Chris Losinger12-Sep-01 9:17
professionalChris Losinger12-Sep-01 9:17 
GeneralRe: Appending integer values to a string? (for Tree labels) Pin
Carlos Antollini12-Sep-01 10:31
Carlos Antollini12-Sep-01 10:31 
GeneralPlease help with memory leak Pin
Craig Miller12-Sep-01 8:53
Craig Miller12-Sep-01 8:53 
Hi,

I'm currently using some code that I found in the forum to write a file to a database and it almost works. It appears that I have some memory leaks that I can't seem to find. Following is the code I'm using which is in a loop. I loop through a directory of images so I can load them into a database.
CFile tmpFile(fileName, CFile::modeRead);
				
//Read from bitmap file into buffer.
LONG nTotalBytes = tmpFile.GetLength();
				
//Allocate a buffer for the input and read from file.
BYTE * inputBuf = new BYTE[nTotalBytes];
UINT nBytesRead = tmpFile.Read(inputBuf, nTotalBytes);
				
CLongBinary cx_LongBinaryImage; 
cx_LongBinaryImage.m_dwDataLength = nTotalBytes; //set the cx_LongBinaryImage.m_hData = GlobalAlloc(GMEM_MOVEABLE,                   nTotalBytes); //allocates a HGLOBAL handle for the CLongBinary object.
				
BYTE* pITemp = (BYTE*) GlobalLock(cx_LongBinaryImage.m_hData); //pITemp is pointing at the address of the HGLOBAL handle
memcpy(pITemp, inputBuf, nTotalBytes); //copy the BYTE array containing the image to the HGLOBAL address
GlobalUnlock(cx_LongBinaryImage.m_hData); //unlock the memory
				
CImageRs* cxTableImage = new CImageRs(); //CRecordset object
if (cxTableImage->Open(NULL)) //opening the database
{
	cxTableImage->AddNew(); //create new record
	cxTableImage->m_MAKE = "Yamaha";
	cxTableImage->m_MODEL = "YZF600RK/RKC";
	cxTableImage->m_YEAR = 1998;
	cxTableImage->m_NAME = FindFileData.cFileName;
	cxTableImage->m_IMAGE.m_dwDataLength = cx_LongBinaryImage.m_dwDataLength;
	cxTableImage->m_IMAGE.m_hData = cx_LongBinaryImage.m_hData;
	cxTableImage->SetFieldNull(&cxTableImage->m_IMAGE, FALSE);
	cxTableImage->SetFieldDirty(&cxTableImage->m_IMAGE, TRUE);
	if(!cxTableImage->Update())
	{
		AfxMessageBox( "Record not added; no field values were set." );
	}
					
	cxTableImage->Close();
}

delete[] inputBuf;


If I call GlobalFree on cx_LongBinaryImage.m_hData I get an error because the CLongBinary calls GlobalFree in it's destructor. Also, when I run this code in the loop I get an error, "Could not update; currently locked by user 'admin' on machine 'MYMACHINE'." This happens when the loop is halfway through the directory, I'm not sure why this is happening. I'm currently developing on Win2000 with VC++ 6.0.

Thanks for any help you can provide,

Craig
GeneralRe: Please help with memory leak Pin
Tim Deveaux12-Sep-01 9:26
Tim Deveaux12-Sep-01 9:26 
GeneralRe: Please help with memory leak Pin
Craig Miller12-Sep-01 10:30
Craig Miller12-Sep-01 10:30 
GeneralRe: Please help with memory leak Pin
Tim Deveaux12-Sep-01 11:05
Tim Deveaux12-Sep-01 11:05 
QuestionHow can i register a .dll or .ocx file in my program similar register it using regsvr32.exe? Pin
12-Sep-01 4:37
suss12-Sep-01 4:37 
AnswerRe: How can i register a .dll or .ocx file in my program similar register it using regsvr32.exe? Pin
12-Sep-01 4:41
suss12-Sep-01 4:41 
AnswerRe: How can i register a .dll or .ocx file in my program similar register it using regsvr32.exe? Pin
Ben M. Stokland12-Sep-01 4:56
Ben M. Stokland12-Sep-01 4:56 
GeneralSHGetSpecialFolderLocation error !!! Pin
Fredb4512-Sep-01 4:09
Fredb4512-Sep-01 4:09 
GeneralWrite some short options into EXE Pin
12-Sep-01 3:57
suss12-Sep-01 3:57 
GeneralRe: Write some short options into EXE Pin
Derek Waters12-Sep-01 14:03
Derek Waters12-Sep-01 14:03 
GeneralRe: Write some short options into EXE Pin
12-Sep-01 18:05
suss12-Sep-01 18:05 
QuestionHow to access Access Base in VC++6.0 Pin
12-Sep-01 3:27
suss12-Sep-01 3:27 
AnswerRe: How to access Access Base in VC++6.0 Pin
Martin Ziacek12-Sep-01 3:46
Martin Ziacek12-Sep-01 3:46 
AnswerRe: How to access Access Base in VC++6.0 Pin
Carlos Antollini12-Sep-01 3:49
Carlos Antollini12-Sep-01 3:49 
Generalunknow output debbug message Pin
12-Sep-01 3:17
suss12-Sep-01 3:17 
GeneralRe: unknow output debbug message Pin
Tomasz Sowinski12-Sep-01 3:26
Tomasz Sowinski12-Sep-01 3:26 
GeneralRe: unknow output debbug message Pin
Carlos Antollini12-Sep-01 3:43
Carlos Antollini12-Sep-01 3:43 
GeneralRe: unknow output debbug message Pin
Rashid Thadha12-Sep-01 5:36
Rashid Thadha12-Sep-01 5:36 

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.