Click here to Skip to main content
15,914,419 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSimultaneous sounds? Pin
Gadjuka8-May-03 23:07
Gadjuka8-May-03 23:07 
AnswerRe: Simultaneous sounds? Pin
G. Steudtel9-May-03 0:54
G. Steudtel9-May-03 0:54 
AnswerRe: Simultaneous sounds? Pin
Anonymous9-May-03 0:55
Anonymous9-May-03 0:55 
GeneralInteraction with ActieveX Pin
andreshs18-May-03 22:43
andreshs18-May-03 22:43 
GeneralExtracting the IStream interface from CFile Pin
Anders Sandberg8-May-03 22:28
Anders Sandberg8-May-03 22:28 
GeneralRe: Extracting the IStream interface from CFile Pin
Anonymous8-May-03 23:17
Anonymous8-May-03 23:17 
GeneralRe: Extracting the IStream interface from CFile Pin
Mike Dimmick9-May-03 6:05
Mike Dimmick9-May-03 6:05 
GeneralRe: Extracting the IStream interface from CFile Pin
Anders Sandberg13-May-03 0:06
Anders Sandberg13-May-03 0:06 
Hi guys! Thanks for your help!

All suggested approaches actually workes.
Trouble though is that Gdiplus::Image::FromStream(IStream* pIstrem)
reads the whole stream to the end. This would have been good if the
stream contained only the image but... Therefore I had to create a new
IStream for the Image::FromStream(.....)

So this is how it came out and thanks aganig for your help:


<br />
Image* SerializeImage(CArchive&, Image*)<br />
{<br />
	DWORD sizeOfStream;<br />
	CFileException* pMemFileError = NULL;<br />
	LPBYTE pMemSpace = NULL;<br />
	DWORD dwPos;<br />
<br />
	CLSID jpgClsid;<br />
	GetEncoderClsid(L"image/jpeg", &jpgClsid);<br />
<br />
	// create a memory file<br />
	COleStreamFile pMemFile;<br />
	if(!pMemFile.CreateMemoryStream(pMemFileError))<br />
		throw pMemFileError;<br />
<br />
	ar.Flush();<br />
	dwPos = ar.GetFile()->GetPosition();<br />
	<br />
	// loadin/storing<br />
	if(ar.IsStoring())<br />
	{<br />
		TRACE("Starts storing Image contents -- pos = %d\n", dwPos);<br />
<br />
		// stream the logo to memoryfile<br />
		pImage->Save(pMemFile.GetStream(),&jpgClsid);<br />
		<br />
		// get the size of the memoryfile<br />
		sizeOfStream = pMemFile.GetLength();<br />
			<br />
		// allocate memory with that size<br />
		pMemSpace = (LPBYTE)CoTaskMemAlloc(sizeOfStream);<br />
<br />
		// set filepointer to beginning of file <br />
		pMemFile.SeekToBegin();<br />
		// read memoryfile contents into memorybuffer<br />
		// and set the sizeofstream to the actual butes read from the stream<br />
		sizeOfStream = pMemFile.Read(pMemSpace,sizeOfStream);<br />
<br />
		// write size to archive <br />
		ar << sizeOfStream;<br />
		// write memorybuffer to archive<br />
		ar.Write(pMemSpace, sizeOfStream);	<br />
		<br />
		dwPos = ar.GetFile()->GetPosition();<br />
		TRACE("Image storing complete -- pos = %d\n", dwPos);<br />
	}<br />
	else // loading<br />
	{<br />
		// get size of image from the archive<br />
		ar >> sizeOfStream;<br />
<br />
		// allocate memory buffer with that size<br />
		pMemSpace = (LPBYTE)CoTaskMemAlloc(sizeOfStream);<br />
<br />
		// read bytes from archive into mem buffer<br />
		ar.Read(pMemSpace, sizeOfStream);<br />
		<br />
		// stream butter into the memoryfile<br />
		pMemFile.Write(pMemSpace, sizeOfStream);<br />
<br />
		// pass the stream to Image::FromStream(...)<br />
		pImage = Image::FromStream(pMemFile.GetStream()); <br />
	<br />
<br />
		// diagnostics<br />
		dwPos = ar.GetFile()->GetPosition();<br />
		if(pImage->GetLastStatus() != Ok)<br />
		{<br />
			AfxMessageBox(	"Misslyckades att läsa in logotype till försättsblad",<br />
							MB_ICONEXCLAMATION);<br />
			delete pImage;<br />
			pImage = NULL;<br />
			TRACE("Image loading failed!! -- pos = %d\n", dwPos);<br />
		}<br />
		else<br />
			TRACE("Image loading complete -- pos = %d\n", dwPos);<br />
	}<br />
	<br />
	// free memory and close memoryfile<br />
	CoTaskMemFree(pMemSpace);<br />
	pMemFile.Close();<br />
	return pImage;<br />
}<br />


/Anders Sandberg
GeneralPls Help.. CFtpFileFind Pin
2249178-May-03 20:27
2249178-May-03 20:27 
GeneralRe: Pls Help.. CFtpFileFind Pin
Mahesh Varma9-May-03 18:33
Mahesh Varma9-May-03 18:33 
GeneralRe: Pls Help.. CFtpFileFind Pin
22491722-Jan-04 1:12
22491722-Jan-04 1:12 
QuestionWhy use ???::??? Pin
alex.barylski8-May-03 20:21
alex.barylski8-May-03 20:21 
AnswerRe: Why use ???::??? Pin
Joseph Dempsey9-May-03 1:12
Joseph Dempsey9-May-03 1:12 
AnswerRe: Why use ???::??? Pin
Mike Dimmick9-May-03 6:21
Mike Dimmick9-May-03 6:21 
GeneralSend mail with SMTP Pin
Mazdak8-May-03 19:27
Mazdak8-May-03 19:27 
GeneralRe: Send mail with SMTP Pin
markkuk9-May-03 0:40
markkuk9-May-03 0:40 
GeneralRe: Send mail with SMTP Pin
Mazdak9-May-03 4:48
Mazdak9-May-03 4:48 
GeneralRe: Send mail with SMTP Pin
Anders Molin9-May-03 1:21
professionalAnders Molin9-May-03 1:21 
GeneralRe: Send mail with SMTP Pin
Mazdak9-May-03 4:48
Mazdak9-May-03 4:48 
GeneralAbout using CopyFileEx( ) Pin
charisma_youn8-May-03 18:01
charisma_youn8-May-03 18:01 
GeneralRe: About using CopyFileEx( ) Pin
Neville Franks9-May-03 12:00
Neville Franks9-May-03 12:00 
GeneralINTERNAL COMPILER ERROR Pin
aguest8-May-03 15:29
aguest8-May-03 15:29 
GeneralRe: INTERNAL COMPILER ERROR Pin
Maxwell Chen8-May-03 16:39
Maxwell Chen8-May-03 16:39 
GeneralRe: INTERNAL COMPILER ERROR Pin
jhwurmbach9-May-03 2:05
jhwurmbach9-May-03 2:05 
GeneralRe: INTERNAL COMPILER ERROR Pin
Roger Allen9-May-03 2:20
Roger Allen9-May-03 2:20 

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.