Anybody tell me how to use IStream correctly?
-
The following is my code which use a IStream interface to dispaly JPEG.But after about 24 hours, an Assert error happened at NO.622 line in atlbase.h ////////////////////////////////////////////////////////////////////////// IStream* pStream=NULL; HGLOBAL hMemory=0; BOOL bIsPicture ; hMemory = ::GlobalAlloc( GMEM_MOVEABLE, iBufferLength ); ASSERT( hMemory != NULL ); LPVOID pData = ::GlobalLock( hMemory ); ASSERT( pData != NULL ); ASSERT(iBufferLength>=0); memcpy(pData,buf,iBufferLength); ::GlobalUnlock(hMemory ); ::CreateStreamOnHGlobal(hMemory,TRUE,&pStream ); ASSERT( pStream != NULL ); //here is other code if(pStream) { pStream->Release(); } if(hMemory) { ::GlobalFree(hMemory); hMemory=NULL; } please contact: ctbpl_xiayi@yahoo.com.cn
-
The following is my code which use a IStream interface to dispaly JPEG.But after about 24 hours, an Assert error happened at NO.622 line in atlbase.h ////////////////////////////////////////////////////////////////////////// IStream* pStream=NULL; HGLOBAL hMemory=0; BOOL bIsPicture ; hMemory = ::GlobalAlloc( GMEM_MOVEABLE, iBufferLength ); ASSERT( hMemory != NULL ); LPVOID pData = ::GlobalLock( hMemory ); ASSERT( pData != NULL ); ASSERT(iBufferLength>=0); memcpy(pData,buf,iBufferLength); ::GlobalUnlock(hMemory ); ::CreateStreamOnHGlobal(hMemory,TRUE,&pStream ); ASSERT( pStream != NULL ); //here is other code if(pStream) { pStream->Release(); } if(hMemory) { ::GlobalFree(hMemory); hMemory=NULL; } please contact: ctbpl_xiayi@yahoo.com.cn
No idea where line 622 is. So I would suggest reading about "Return Values" and making proper use of them. Todd Smith
-
The following is my code which use a IStream interface to dispaly JPEG.But after about 24 hours, an Assert error happened at NO.622 line in atlbase.h ////////////////////////////////////////////////////////////////////////// IStream* pStream=NULL; HGLOBAL hMemory=0; BOOL bIsPicture ; hMemory = ::GlobalAlloc( GMEM_MOVEABLE, iBufferLength ); ASSERT( hMemory != NULL ); LPVOID pData = ::GlobalLock( hMemory ); ASSERT( pData != NULL ); ASSERT(iBufferLength>=0); memcpy(pData,buf,iBufferLength); ::GlobalUnlock(hMemory ); ::CreateStreamOnHGlobal(hMemory,TRUE,&pStream ); ASSERT( pStream != NULL ); //here is other code if(pStream) { pStream->Release(); } if(hMemory) { ::GlobalFree(hMemory); hMemory=NULL; } please contact: ctbpl_xiayi@yahoo.com.cn
Hi there The line 622 in atlbase.h is the -> operator of the CComQIPtr< > class template, and I don't see you are using any instance of it in the code you posted, so I suggest you to open the "Call stack" (Alt + 7) when you get the assert, and follow you way up until you reach the line in your code which is calling the -> operator on an instance of CComQIPtr<>, and then take a look why that pointer is NULL. Regards, Fabian