Example #1
0
File: zipk.cpp Project: wangch/zipk
static Gdiplus::Image* bkimg(int rcid) {
   HRSRC hrsc = ::FindResource(hInst, MAKEINTRESOURCE(rcid), TEXT("PNG"));
   DWORD size = ::SizeofResource(hInst, hrsc);
   LPVOID hg = ::LoadResource(hInst, hrsc);
   HGLOBAL mem = ::GlobalAlloc(GMEM_MOVEABLE, size);
   Gdiplus::Image* img = 0;
   if (mem) {
      LPVOID pmem = ::GlobalLock(mem);
      if (pmem) {
         ::CopyMemory(pmem, hg, size);
         LPSTREAM is;
         if (::CreateStreamOnHGlobal(pmem, FALSE, &is) == S_OK) {
            Gdiplus::Image* m = new Gdiplus::Image(is);
            is->Release();
            if (m->GetLastStatus() != Gdiplus::Ok) {
               delete m;
               return img;
            }
            img = m;
         }
         ::GlobalUnlock(mem);
      }
      ::GlobalFree(mem);
   }
   return img;
}
Example #2
0
void CScratchPadDlg::LoadSrcImage()
{
	HINSTANCE hResInstance = AfxGetResourceHandle( );

	HRSRC res = FindResource(hResInstance,
		MAKEINTRESOURCE(IDB_BITMAP1),L"BINARY");
	if (res) 
	{
		HGLOBAL mem = LoadResource(hResInstance, res);
		void *data = LockResource(mem);
		size_t len = SizeofResource(hResInstance, res);

		HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, len);
		LPVOID pvData = GlobalLock( hGlobal );
		memcpy(pvData,data,len);
		GlobalUnlock(hGlobal);

		LPSTREAM pStream = NULL;
		HRESULT hr = CreateStreamOnHGlobal( hGlobal, TRUE, &pStream );

		using namespace Gdiplus;
		m_pSrcBitmap = new Bitmap(pStream,false);

		pStream->Release();
	}
}
Example #3
0
BOOL FileUpload(Zimbra::Rpc::ZimbraConnection *z_connection, LPWSTR *ppwszToken)
{
    LOGFN_INTERNAL_NO;

    LPSTR pszTestFile = "E:\\temp\\aa.log";
    LPSTREAM pStreamFile = NULL;
    HRESULT hr = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, STGM_READ,
        (LPWSTR)pszTestFile, NULL, &pStreamFile);

    if (FAILED(hr))
    {
        LOG_ERROR(_T("failed to OpenStreamOnFile call: %x"), hr);
        return FALSE;
    }

    HANDLE hFile = CreateFile(L"E:\\temp\\aa.log", GENERIC_READ, FILE_SHARE_READ, NULL,
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    DWORD dwFileSize = GetFileSize(hFile, NULL);

    CloseHandle(hFile);
    _tprintf(_T("  File Upload size=%d bytes\n"), dwFileSize);

    BOOL bResult = z_connection->DoFileUpload(pStreamFile, dwFileSize,
        L"/service/upload?fmt=raw", ppwszToken, NULL);

    pStreamFile->Release();

    return bResult;
}
HRESULT STDMETHODCALLTYPE CXMLDocument::Load(/* [in] */ LPSTREAM pStm)
{
	if (pStm == NULL)
	{
		return E_INVALIDARG;
	}

	// Load the XML from the stream
	STATSTG statstg;
	pStm->Stat(&statstg, STATFLAG_NONAME);

	ULONG cbBufSize = statstg.cbSize.LowPart;

	char *pBuffer = new char[cbBufSize];
	if (pBuffer == NULL)
	{
		return E_OUTOFMEMORY;
	}

	memset(pBuffer, 0, cbBufSize);
	pStm->Read(pBuffer, cbBufSize, NULL);

	m_spRoot.Release();
	ParseExpat(pBuffer, cbBufSize, (IXMLDocument *) this, &m_spRoot);

	delete []pBuffer;

	m_nReadyState = READYSTATE_LOADED;

	return S_OK;
}
Example #5
0
LPSTREAM AFXAPI _AfxLoadStreamFromPropset(CPropertySection& psec, LPCTSTR pszPropName,
	DWORD& vtType)
{
	ASSERT(AfxIsValidString(pszPropName));

	vtType = VT_EMPTY;

	DWORD dwPropID;
	CProperty* pprop = NULL;
	LPSTREAM pstm = NULL;

	if (psec.GetID(pszPropName, &dwPropID) &&
		((pprop = psec.GetProperty(dwPropID)) != NULL))
	{
		vtType = pprop->GetType();

		if ((vtType == VT_BLOB) || (vtType == VT_BLOB_PROPSET))
		{
			pstm = _AfxCreateMemoryStream();

			if (pstm != NULL)
			{
				if (!_AfxInitStreamDataFromBlobProp(pstm, pprop))
				{
					pstm->Release();
					pstm = NULL;
				}
			}
		}
	}

	return pstm;
}
Example #6
0
STDMETHODIMP VLCPersistStorage::Save(LPSTORAGE pStg, BOOL fSameAsLoad)
{
    if( NULL == pStg )
        return E_INVALIDARG;

    if( fSameAsLoad && (S_FALSE == IsDirty()) )
        return S_OK;

    LPSTREAM pStm = NULL;
    HRESULT result = pStg->CreateStream(L"VideoLAN ActiveX Plugin Data",
                        STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStm);

    if( FAILED(result) )
        return result;

    LPPERSISTSTREAMINIT pPersistStreamInit;
    if( SUCCEEDED(QueryInterface(IID_IPersistStreamInit, (void **)&pPersistStreamInit)) )
    {
        result = pPersistStreamInit->Save(pStm, fSameAsLoad);
        pPersistStreamInit->Release();
    }

    pStm->Release();

    return result;
};
Example #7
0
FARINTERNAL UtDIBFileStmToPBrushNativeStm
	(LPSTREAM pstmDIBFile, LPSTREAM pstmPBrush)
{
	BITMAPFILEHEADER bfh;
	HRESULT	error;
	
	if (error = pstmDIBFile->Read(&bfh, sizeof(bfh), 0))
		return error;
	
	// seek to the begining of the stream
	LARGE_INTEGER large_int;
	LISet32( large_int, 0);
	if (error = pstmDIBFile->Seek(large_int, STREAM_SEEK_SET, 0))
		return error;
	
	if (error = pstmPBrush->Write(&(bfh.bfSize), sizeof(DWORD), 0))
		return error;
	
	ULARGE_INTEGER ularge_int;
	ULISet32(ularge_int, bfh.bfSize);
	
	if ((error = pstmDIBFile->CopyTo(pstmPBrush, ularge_int,
			NULL, NULL)) == NOERROR)
		StSetSize(pstmPBrush, 0, TRUE);
	
	return error;
}
Example #8
0
BOOL CSummInfo::ReadFromStorage(LPSTORAGE lpRootStg)
{
	if (lpRootStg != NULL)
	{
		LPSTREAM lpStream = NULL;

		if (FAILED(lpRootStg->OpenStream(szSummInfo,
				   NULL, STGM_SHARE_EXCLUSIVE|STGM_READ,
				   0, &lpStream)))
		{
			TRACE(_T("OpenStream failed\n"));
			return FALSE;
		}
		else
		{
			if (!m_propSet.ReadFromStream(lpStream))
			{
				TRACE(_T("ReadFromStream failed\n"));
				return FALSE;
			}
			m_pSection = m_propSet.GetSection(FMTID_SummaryInformation);
			lpStream->Release();
			return TRUE;
		}
	}
	return FALSE;
}
Example #9
0
FARINTERNAL UtPlaceableMFStmToMSDrawNativeStm
	(LPSTREAM pstmPMF, LPSTREAM pstmMSDraw)
{
	DWORD	dwSize;	// size of metafile bits excluding the placeable MF header
	LONG	xExt;
	LONG	yExt;
	WORD	wBuf[5]; // dwSize(DWORD), mm(int), xExt(int), yExt(int)
	HRESULT error;
	
	if (error = UtGetSizeAndExtentsFromPlaceableMFStm(pstmPMF, &dwSize,
			&xExt, &yExt))
		return error;		

	*((DWORD FAR*) wBuf) = dwSize + 3*sizeof(WORD);
	wBuf[2] = MM_ANISOTROPIC;
	wBuf[3] = (int) xExt;
	wBuf[4] = (int) yExt;
	
	if (error = pstmMSDraw->Write(wBuf, sizeof(wBuf), 0))
		return error;

	ULARGE_INTEGER ularge_int;
	ULISet32(ularge_int, dwSize);
	if ((error = pstmPMF->CopyTo(pstmMSDraw, ularge_int,
			NULL, NULL)) == NOERROR)
		StSetSize(pstmMSDraw, 0, TRUE);
	
	return error;
				
}
Example #10
0
BOOL CSummInfo::WriteToStorage(LPSTORAGE lpRootStg)
{
	if (lpRootStg != NULL)
	{
		LPSTREAM lpStream = NULL;
		if (FAILED(lpRootStg->CreateStream(szSummInfo,
				   STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE,
				   0, 0, &lpStream)))
		{
			TRACE(_T("CreateStream failed\n"));
			return FALSE;
		}
		else
		{
			if(!m_propSet.WriteToStream(lpStream))
			{
				TRACE(_T("WriteToStream failed\n"));
				return FALSE;
			}
			lpRootStg->Commit(STGC_DEFAULT);
			lpStream->Release();
			return TRUE;
		}
	}
	return FALSE;
}
Example #11
0
	HRESULT STDMETHODCALLTYPE TinySmiley::SaveAs(LPSTREAM pStm)//默认保存第一帧到文件流
	{
		if (!pStm) return S_FALSE;
		if (m_images.size() == 0) return S_FALSE;

		BITMAP bitmap = { 0 };
		if (!GetObject(m_images[0], sizeof(BITMAP), (LPSTR)&bitmap))
			return S_FALSE;
		BITMAPINFOHEADER bi = { 0 };
		bi.biSize = sizeof(BITMAPINFOHEADER);
		bi.biWidth = bitmap.bmWidth;
		bi.biHeight = bitmap.bmHeight;
		bi.biPlanes = 1;
		bi.biBitCount = bitmap.bmBitsPixel;
		bi.biCompression = BI_RGB;
		DWORD size = bitmap.bmWidthBytes * bitmap.bmHeight;
		BITMAPFILEHEADER bfh = { 0 };
		bfh.bfType = 0x4d42;
		bfh.bfOffBits = min(14, sizeof(BITMAPFILEHEADER)) + sizeof(BITMAPINFOHEADER) + bi.biClrUsed * sizeof(RGBQUAD);
		bfh.bfSize = bfh.bfOffBits + bitmap.bmWidthBytes*bitmap.bmHeight;
		ULARGE_INTEGER libSize;
		libSize.LowPart = bfh.bfSize;
		pStm->SetSize(libSize);
		ULONG cbWritten = 0;
		pStm->Write(&bfh, min(14, sizeof(BITMAPFILEHEADER)), &cbWritten);
		pStm->Write(&bi, bi.biSize, &cbWritten);
		pStm->Write(bitmap.bmBits, bitmap.bmWidthBytes*bitmap.bmHeight, &cbWritten);
		return S_OK;
	}
Example #12
0
bool MAPIContact::SetNotes(const String &szNotes, bool bRTF) {
#ifdef _WIN32_WCE
	return SetPropertyString(PR_BODY, szNotes);
#else
	if(!Contact() || IsNull(szNotes)) 
		return false;
	ULONG nLen = (ULONG)szNotes.GetLength();

	HRESULT hr = E_FAIL;
	LPSTREAM pStream = NULL;
	if(bRTF) {
		if(Contact()->OpenProperty(PR_RTF_COMPRESSED, &IID_IStream, STGM_CREATE | STGM_WRITE, 
								MAPI_MODIFY | MAPI_CREATE, (LPUNKNOWN*)&pStream) == S_OK) {
			IStream *pUncompressed;
			if(WrapCompressedRTFStream(pStream,MAPI_MODIFY, &pUncompressed) == S_OK) {
				hr = pUncompressed->Write(szNotes, nLen*sizeof(TCHAR), NULL);
				if(pUncompressed->Commit(STGC_DEFAULT)==S_OK) 
					pStream->Commit(STGC_DEFAULT);
				RELEASE(pUncompressed);
			}
		}
	} else {
		if(Contact()->OpenProperty(PR_BODY, &IID_IStream, 0, MAPI_MODIFY | MAPI_CREATE, 
																(LPUNKNOWN*)&pStream) == S_OK) 
			hr = pStream->Write(szNotes, (nLen+1)*sizeof(TCHAR), NULL);
	}
	RELEASE(pStream);
	return (hr == S_OK);
#endif
}
Example #13
0
BOOL CGifImage::LoadFromBuffer(const BYTE* lpBuf, DWORD dwSize)
{
	if (NULL == lpBuf || dwSize <= 0)
		return FALSE;

	HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize);
	if (NULL == hGlobal)
		return FALSE;

	LPVOID lpBuffer = ::GlobalLock(hGlobal);
	if (NULL == lpBuffer)
	{
		::GlobalFree(hGlobal);
		return FALSE;
	}

	memcpy(lpBuffer, lpBuf, dwSize);
	::GlobalUnlock(hGlobal);

	LPSTREAM lpStream = NULL;
	HRESULT hr = ::CreateStreamOnHGlobal(hGlobal, TRUE, &lpStream);
	if (hr != S_OK)
	{
		::GlobalFree(hGlobal);
		return FALSE;
	}

	BOOL bRet = LoadFromIStream(lpStream);
	lpStream->Release();

	return bRet;
}
Example #14
0
BOOL CImageEx::LoadFromResource(HINSTANCE hInstance, LPCTSTR pszResourceName, LPCTSTR pszResType)
{
	HRSRC hRsrc = ::FindResource(hInstance, pszResourceName, pszResType);
	if (NULL == hRsrc)
		return FALSE;

	DWORD dwSize = ::SizeofResource(hInstance, hRsrc); 
	if (0 == dwSize)
		return FALSE;

	HGLOBAL hGlobal = ::LoadResource(hInstance, hRsrc); 
	if (NULL == hGlobal)
		return FALSE;

	LPVOID pBuffer = ::LockResource(hGlobal);
	if (NULL == pBuffer)
	{
		::FreeResource(hGlobal);
		return FALSE;
	}

	HGLOBAL hGlobal2 = ::GlobalAlloc(GHND, dwSize);
	if (NULL == hGlobal2)
	{
		::FreeResource(hGlobal);
		return FALSE;
	}

	LPVOID pBuffer2 = ::GlobalLock(hGlobal2);
	if (NULL == pBuffer2)
	{
		::GlobalFree(hGlobal2);
		::FreeResource(hGlobal);
		return FALSE;
	}

	memcpy(pBuffer2, pBuffer, dwSize);
	::GlobalUnlock(hGlobal2);

	LPSTREAM pStream = NULL;
	HRESULT hr = ::CreateStreamOnHGlobal(hGlobal2, TRUE, &pStream);
	if (hr != S_OK)
	{
		::GlobalFree(hGlobal2);
		::FreeResource(hGlobal);
		return FALSE;
	}

	BOOL bRet = LoadFromIStream(pStream);

	if (pStream)
		pStream->Release();

	::FreeResource(hGlobal);

	return bRet;
}
Example #15
0
/*static */
bool display_t::save_bitmap(const char *szFileName, HBITMAP bmp, HPALETTE pal /*= NULL*/)
{
	START_FUNCTION_BOOL();

	PICTDESC pdPictDesc;
	pdPictDesc.cbSizeofstruct = sizeof(PICTDESC);
	pdPictDesc.picType = PICTYPE_BITMAP;
	pdPictDesc.bmp.hbitmap = bmp;
	pdPictDesc.bmp.hpal = pal;

	LPPICTURE plPicture = NULL;
	HRESULT hResult = OleCreatePictureIndirect(&pdPictDesc, IID_IPicture, false, reinterpret_cast<void**>(&plPicture));

	if (!SUCCEEDED(hResult))
	{
		break;
	}

	LPSTREAM lpStream = NULL;
	hResult = CreateStreamOnHGlobal(0, true, &lpStream);

	if (!SUCCEEDED(hResult))
	{
		plPicture->Release();
		return false;
	}

	LONG lBytesStreamed = 0;
	hResult = plPicture->SaveAsFile(lpStream, true, &lBytesStreamed);

	HANDLE hFile = CreateFileA(szFileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
		CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

	if (!SUCCEEDED(hResult) || !hFile)
	{
		lpStream->Release();
		plPicture->Release();
		break;
	}

	HGLOBAL hgMemory = 0;
	GetHGlobalFromStream(lpStream, &hgMemory);
	LPVOID lpData = GlobalLock(hgMemory);

	DWORD dwBytesWritten = 0;

	bool bResult = !!WriteFile(hFile, lpData, lBytesStreamed, &dwBytesWritten, 0);
	bResult &= (dwBytesWritten == static_cast<DWORD>(lBytesStreamed));

	GlobalUnlock(hgMemory);
	CloseHandle(hFile);

	lpStream->Release();
	plPicture->Release();

	END_FUNCTION_BOOL();
}
Example #16
0
STDMETHODIMP CValueAxis::Load(LPSTREAM pStm)
{
	pStm->Read(&m_iWholeDigits, sizeof(int), NULL);
	pStm->Read(&m_iDecimalDigits, sizeof(int), NULL);

	pStm->Read(&m_dMinVal, sizeof(double), NULL);
	pStm->Read(&m_dMaxVal, sizeof(double), NULL);

	return CAxis::Load(pStm);
}
Example #17
0
STDMETHODIMP CValueAxis::Save(LPSTREAM pStm, BOOL fClearDirty)
{
	pStm->Write(&m_iWholeDigits, sizeof(int), NULL);
	pStm->Write(&m_iDecimalDigits, sizeof(int), NULL);

	pStm->Write(&m_dMinVal, sizeof(double), NULL);
	pStm->Write(&m_dMaxVal, sizeof(double), NULL);

	return CAxis::Save(pStm, fClearDirty);
}
/////////////////////////////////////////////////////////////////////////////////////////
// Utility to save a bitmap to file for later examination. Used for debugging only.
// Based on an article by "gelbert" on www.experts-exchange.com at
// http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20193761.html
//
// This version is a member function and instead of taking an HBITMAP as the 2nd
// parameter, it take a reference to a CBitmap. Otherwise, it is identical.
/////////////////////////////////////////////////////////////////////////////////////////
BOOL CSliderCtrlEx::SaveBitmap(LPCSTR lpFileName, CBitmap &hBitmap, HPALETTE hPal)
{
	BOOL bResult = FALSE;
	
	PICTDESC stPictDesc;
	stPictDesc.cbSizeofstruct = sizeof(PICTDESC);
	stPictDesc.picType = PICTYPE_BITMAP;
	stPictDesc.bmp.hbitmap = hBitmap;
	stPictDesc.bmp.hpal = hPal;
	
	LPPICTURE pPicture;
	HRESULT hr = OleCreatePictureIndirect( &stPictDesc, IID_IPicture, FALSE,
		reinterpret_cast<void**>(&pPicture) );
	if ( SUCCEEDED(hr) )
	{
		LPSTREAM pStream;
		hr = CreateStreamOnHGlobal( NULL, TRUE, &pStream );
		if ( SUCCEEDED(hr) )
		{
			long lBytesStreamed = 0;
			hr = pPicture->SaveAsFile( pStream, TRUE, &lBytesStreamed );
			if ( SUCCEEDED(hr) )
			{
				HANDLE hFile = CreateFile(_T(lpFileName), 
					GENERIC_WRITE, 
					FILE_SHARE_READ, 
					NULL,
					CREATE_ALWAYS, 
					FILE_ATTRIBUTE_NORMAL, 
					NULL );
				if ( hFile )
				{
					HGLOBAL hMem = NULL;
					GetHGlobalFromStream( pStream, &hMem );
					LPVOID lpData = GlobalLock( hMem );
					
					DWORD dwBytesWritten;
					bResult = WriteFile( hFile, lpData, lBytesStreamed, &dwBytesWritten, NULL );
					bResult &= ( dwBytesWritten == (DWORD)lBytesStreamed );
					
					// clean up
					GlobalUnlock(hMem);
					CloseHandle(hFile);
				}
			}
			// clean up         
			pStream->Release();
		}
		// clean up      
		pPicture->Release();
	}
	
	return bResult;   
}
Example #19
0
BOOL COleServerItem::GetLinkSourceData(LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

	LPOLEOBJECT lpOleObject = GetOleObject();
	ASSERT(lpOleObject != NULL);

	// get moniker from ole object
	LPMONIKER lpMoniker;
	SCODE sc = lpOleObject->GetMoniker(OLEGETMONIKER_TEMPFORUSER,
		OLEWHICHMK_OBJFULL, &lpMoniker);
	if (sc != S_OK)
	{
		TRACE0("Warning: unable to get moniker for object.\n");
		return FALSE;
	}
	ASSERT(lpMoniker != NULL);

	// create a memory based stream to write the moniker to
	LPSTREAM lpStream;
	if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK)
	{
		lpMoniker->Release();
		AfxThrowMemoryException();
	}
	ASSERT(lpStream != NULL);

	// write the moniker to the stream, and add it to the clipboard
	sc = ::OleSaveToStream(lpMoniker, lpStream);
	lpMoniker->Release();
	if (sc != S_OK)
	{
		lpStream->Release();
		AfxThrowOleException(sc);
	}

	// write the class ID of the document to the stream as well
	COleLinkingDoc* pDoc = GetDocument();
	ASSERT(pDoc->m_pFactory != NULL);
	sc = WriteClassStm(lpStream, pDoc->m_pFactory->GetClassID());
	if (sc != S_OK)
	{
		lpStream->Release();
		AfxThrowOleException(sc);
	}

	// setup the STGMEDIUM
	lpStgMedium->tymed = TYMED_ISTREAM;
	lpStgMedium->pstm = lpStream;
	lpStgMedium->pUnkForRelease = NULL;
	return TRUE;
}
Example #20
0
STDMETHODIMP CAxis::Load(LPSTREAM pStm)
{
	m_bstrDisplayFormat.ReadFromStream(pStm);
	m_bstrTitle.ReadFromStream(pStm);
	pStm->Read(&m_lNumTicks, sizeof(m_lNumTicks), NULL);
	pStm->Read(&m_bShowAxis, sizeof(m_bShowAxis), NULL);
	pStm->Read(&m_bShowTitle, sizeof(m_bShowTitle), NULL);
	pStm->Read(&m_clrAxis, sizeof(m_clrAxis), NULL);
	pStm->Read(&m_clrTitle, sizeof(m_clrTitle), NULL);

	ReadFontFromStream(&m_spTickFont, pStm);
	ReadFontFromStream(&m_spTitleFont, pStm);

	return S_OK;
}
Example #21
0
STDMETHODIMP CAxis::Save(LPSTREAM pStm, BOOL fClearDirty)
{
	m_bstrDisplayFormat.WriteToStream(pStm);
	m_bstrTitle.WriteToStream(pStm);
	pStm->Write(&m_lNumTicks, sizeof(m_lNumTicks), NULL);
	pStm->Write(&m_bShowAxis, sizeof(m_bShowAxis), NULL);
	pStm->Write(&m_bShowTitle, sizeof(m_bShowTitle), NULL);
	pStm->Write(&m_clrAxis, sizeof(m_clrAxis), NULL);
	pStm->Write(&m_clrTitle, sizeof(m_clrTitle), NULL);

	SaveFontToStream(m_spTickFont, pStm);
	SaveFontToStream(m_spTitleFont, pStm);
			
	return S_OK;
}
Example #22
0
void ReadStorage(LPSTORAGE pStg)
// reads one storage -- recursive calls for substorages
{
    USES_CONVERSION;
    LPSTORAGE pSubStg = NULL;
    LPSTREAM pStream = NULL;
    LPENUMSTATSTG pEnum = NULL;
    LPMALLOC pMalloc = NULL; // for freeing statstg
    STATSTG statstg;
    ULONG nLength;
    BYTE buffer[101];

    g_nIndent++;
    ::CoGetMalloc(MEMCTX_TASK, &pMalloc); // assumes AfxOleInit
                                          //  was called
    VERIFY(pStg->EnumElements(0, NULL, 0, &pEnum) == S_OK);
    while (pEnum->Next(1, &statstg, NULL) == S_OK) {
      if (statstg.type == STGTY_STORAGE) {
        VERIFY(pStg->OpenStorage(statstg.pwcsName, NULL,
               STGM_READ | STGM_SHARE_EXCLUSIVE,
               NULL, 0, &pSubStg) == S_OK);
        ASSERT(pSubStg != NULL);
        TRACE("%0.*sStorage = %s\n", (g_nIndent - 1) * 4,
              g_szBlanks, OLE2CT(statstg.pwcsName));
        ReadStorage(pSubStg);
        pSubStg->Release();
      }
      else if (statstg.type == STGTY_STREAM) {
        VERIFY(pStg->OpenStream(statstg.pwcsName, NULL,
               STGM_READ | STGM_SHARE_EXCLUSIVE,
               0, &pStream) == S_OK);
        ASSERT(pStream != NULL);
        TRACE("%0.*sStream = %s\n", (g_nIndent - 1) * 4,
               g_szBlanks, OLE2CT(statstg.pwcsName));
        pStream->Read(buffer, 100, &nLength);
        buffer[nLength] = '\0';
        TRACE("%s\n", buffer);
        pStream->Release();
      }
      else {
        ASSERT(FALSE);  // LockBytes?
      }
      pMalloc->Free(statstg.pwcsName); // avoids memory leaks
    }
    pMalloc->Release();
    pEnum->Release();
    g_nIndent--;
}
Example #23
0
STDMETHODIMP CTimeAxis::Save(LPSTREAM pStm, BOOL fClearDirty)
{
	double dTimeSpan = m_dMaxVal - m_dMinVal;
	pStm->Write(&dTimeSpan, sizeof(double), NULL);

	return CAxis::Save(pStm, fClearDirty);
}
Example #24
0
STDMETHODIMP CTimeAxis::Load(LPSTREAM pStm)
{
	double dTimeSpan;
	pStm->Read(&dTimeSpan, sizeof(double), NULL);
	m_dMinVal = m_dMaxVal - dTimeSpan;

	return CAxis::Load(pStm);
}
Example #25
0
STDMETHODIMP CZ80Assembler::Assemble(VARIANT varInput, int *lpInt)
{
	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, output_buf_size); 
	output_contents = (unsigned char *) GlobalLock(hGlobal);

	if (V_VT(&varInput) == VT_BSTR)
	{
		mode = MODE_NORMAL | MODE_COMMANDLINE;

		CW2CT szInput(V_BSTR(&varInput));
		input_contents = strdup(szInput);
	}
	else
	{
		mode = MODE_NORMAL;

		if (curr_input_file) {
			free(curr_input_file);
		}
		curr_input_file = strdup(m_bstrInputFile);
		if (output_filename) {
			free(output_filename);
		}
		output_filename = strdup(m_bstrOutputFile);
	}

	*lpInt = run_assembly();

	GlobalUnlock(hGlobal);

	if (m_pStmOutput != NULL)
	{
		m_pStmOutput->Release();
	}

	LPSTREAM pStream = NULL;
	HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
	ULARGE_INTEGER ul;
	ul.QuadPart = out_ptr - output_contents;
	pStream->SetSize(ul);
	
	m_pStmOutput = pStream;

	return S_OK;
}
Example #26
0
STDMETHODIMP CGrid::Load(LPSTREAM pStm)
{
    pStm->Read(&m_bShowVertical, sizeof(m_bShowVertical), NULL);
    pStm->Read(&m_bShowHorizontal, sizeof(m_bShowHorizontal), NULL);
    pStm->Read(&m_lNumberOfVerticalLines, sizeof(m_lNumberOfVerticalLines), NULL);
    pStm->Read(&m_lNumberOfHorizontalLines, sizeof(m_lNumberOfHorizontalLines), NULL);
    pStm->Read(&m_enumVerticalStyle, sizeof(m_enumVerticalStyle), NULL);
    pStm->Read(&m_enumHorizontalStyle, sizeof(m_enumHorizontalStyle), NULL);
    pStm->Read(&m_nWidth, sizeof(m_nWidth), NULL);
    pStm->Read(&m_clrVerticalColor, sizeof(m_clrVerticalColor), NULL);
    pStm->Read(&m_clrHorizontalColor, sizeof(m_clrHorizontalColor), NULL);

    return S_OK;
}
Example #27
0
STDMETHODIMP CGrid::Save(LPSTREAM pStm, BOOL fClearDirty)
{
    pStm->Write(&m_bShowVertical, sizeof(m_bShowVertical), NULL);
    pStm->Write(&m_bShowHorizontal, sizeof(m_bShowHorizontal), NULL);
    pStm->Write(&m_lNumberOfVerticalLines, sizeof(m_lNumberOfVerticalLines), NULL);
    pStm->Write(&m_lNumberOfHorizontalLines, sizeof(m_lNumberOfHorizontalLines), NULL);
    pStm->Write(&m_enumVerticalStyle, sizeof(m_enumVerticalStyle), NULL);
    pStm->Write(&m_enumHorizontalStyle, sizeof(m_enumHorizontalStyle), NULL);
    pStm->Write(&m_nWidth, sizeof(m_nWidth), NULL);
    pStm->Write(&m_clrVerticalColor, sizeof(m_clrVerticalColor), NULL);
    pStm->Write(&m_clrHorizontalColor, sizeof(m_clrHorizontalColor), NULL);

    return S_OK;
}
Example #28
0
LPFONT AFXAPI _AfxCreateFontFromStream(LPSTREAM pstm)
{
	BOOL bSuccess = FALSE;
	LPFONT pFont = NULL;
	LPPERSISTSTREAM pPersStm = NULL;
	CLSID clsid;

	if (SUCCEEDED(pstm->Read(&clsid, sizeof(CLSID), NULL)))
	{
		HRESULT hr;

		if (IsEqualCLSID(clsid, CLSID_StdFont) ||
			IsEqualCLSID(clsid, _afx_CLSID_StdFont_V1))
		{
			// We know this kind of font; create it using the API.
			hr = ::OleCreateFontIndirect((LPFONTDESC)&_afxFontDescHelv, IID_IFont,
					(LPVOID*)&pFont);
		}
		else
		{
			// Some other implementation of IFont.
			hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IFont,
					(LPVOID*)&pFont);
		}

		if (SUCCEEDED(hr))
		{
			// Successfully created font, now get its IPersistStream interface.

			ASSERT_POINTER(pFont, IFont);

			if (SUCCEEDED(pFont->QueryInterface(IID_IPersistStream,
					(LPVOID*)&pPersStm)))
			{
				ASSERT_POINTER(pPersStm, IPersistStream);
			}
		}

		if (pPersStm != NULL)
		{
			// Load the font.

			ASSERT_POINTER(pFont, IFont);
			bSuccess = SUCCEEDED(pPersStm->Load(pstm));
			pPersStm->Release();
		}
	}

	// If we failed for any reason, clean up the font.
	if (!bSuccess && pFont != NULL)
	{
		pFont->Release();
		pFont = NULL;
	}

	return pFont;
}
Example #29
0
HRESULT CGifSmileyCtrl::IPersistStreamInit_Save(LPSTREAM pStm, BOOL fClearDirty,const ATL_PROPMAP_ENTRY* pMap)
{
	INFO_GIF infoGif;;
	wsprintf(infoGif.filePath, m_strFilename.GetBuffer());
	infoGif.hwndFrom = (LONG)m_hwndParent;
	infoGif.clrBackground = m_clrBackColor;
	pStm->Write(&infoGif, sizeof(INFO_GIF),NULL);
	return IPersistStreamInitImpl<CGifSmileyCtrl>::IPersistStreamInit_Save( pStm, fClearDirty, pMap);
}
Example #30
0
/// @brief ÉèÖÃGIF¶¯»­Í¼Æ¬,´Ó×ÊÔ´ÖмÓÔØͼƬ.
/// @param hEle  ÔªËؾä±ú.
/// @param id    ×ÊÔ´ID.
/// @param pType ×ÊÔ´ÀàÐÍ.
void WINAPI XGif_SetImageRes(HELE hEle,int id,wchar_t *pType)
{
	IsGifDebug(hEle,__FUNCTION__);
	gif_ *pObject=(gif_*)hEle;

	if(pObject->pGif)
	{
		delete pObject->pGif;
		pObject->pGif=NULL;
	}

	if(pType)
	{
		HMODULE hInst=GetModuleHandle(NULL);
		wchar_t * lpRes=MAKEINTRESOURCE(id); 
		HRSRC   hRsrc=::FindResource(hInst,lpRes,pType);
		if(NULL==hRsrc) return ;
		HGLOBAL hGlobal=LoadResource(hInst,hRsrc);
		DWORD   dwSize   =SizeofResource(hInst,hRsrc); 
		LPVOID   lpData  =LockResource(hGlobal);
		HGLOBAL   hJPG   =   ::GlobalAlloc(GMEM_MOVEABLE,   dwSize); 
		LPVOID   lpJGP   =   ::GlobalLock(hJPG); 
		memcpy(lpJGP,   lpData,   dwSize); 
		::GlobalUnlock(hJPG);
		LPSTREAM   pstm =NULL;
		HRESULT   hr   =CreateStreamOnHGlobal(hJPG,   TRUE,   &pstm); 
		assert(SUCCEEDED(hr)   &&   pstm); 

		pObject->pGif=new ImageEx(pstm);

		pstm->Release();

		BOOL hrr=FreeResource(hGlobal);

		if(Gdiplus::Ok != (pObject->pGif->GetLastStatus()))
		{
			delete pObject->pGif;
			pObject->pGif=NULL;
		}

		if(pObject->pGif->InitAnimation(0,0))
			SetTimer(XEle_GetHWnd(hEle),(int)hEle,100,Gif_TimerProc);
	}
}