home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / ACTIVEX / SRDVID / DATA.1 / utility.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  4.6 KB  |  204 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //    utility.cpp : Implementation of the utility unit
  4. //
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. //  (C) Copyright Black Diamond Consulting, Inc 1996. All rights reserved.
  8. //
  9. //    You have a royalty-free right to use, modify, reproduce and 
  10. //    distribute the Sample Files (and/or any modified version) in 
  11. //    any way you find useful, provided that you agree that Black 
  12. //    Diamond Consulting has no warranty obligations or liability
  13. //    for any Sample Application Files which are modified. 
  14. //
  15. //    Revision History:
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18.  
  19. #include "stdafx.h"
  20.  
  21. #include "dib.h"
  22.  
  23. #ifndef __UTILITY_H__
  24.     #include "utility.h"
  25. #endif 
  26.  
  27. #ifdef _DEBUG
  28.     #undef THIS_FILE
  29.     static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. void InfoMsg( LPCSTR sz, ... )
  33. {
  34.     char buffer[256];
  35.  
  36.     wvsprintf( buffer, sz, (LPSTR)(&sz+1) );
  37.     ::MessageBeep( MB_ICONQUESTION );
  38.     ::MessageBox( NULL, buffer, "Information", MB_OK|MB_ICONQUESTION|MB_TASKMODAL );
  39. }
  40.  
  41. void ErrMsg( LPCSTR sz, ... )
  42. {
  43.     char buffer[256];
  44.  
  45.     wvsprintf( buffer, sz, (LPSTR)(&sz+1) );
  46.     ::MessageBeep( MB_ICONHAND );
  47.     ::MessageBox( NULL, buffer, "Application Error", MB_OK|MB_ICONHAND|MB_TASKMODAL );
  48. }
  49.  
  50. void DebugMsg( LPCSTR sz, ... )
  51. {
  52.     char buffer[256];
  53.  
  54.     wvsprintf( buffer, sz, (LPSTR)(&sz+1) );
  55.     OutputDebugString( buffer );
  56. }
  57.  
  58. HRESULT ReadFromStream( LPSTREAM pIStream, CString& string )
  59. {
  60.     HRESULT hr;
  61.     unsigned long size;
  62.     
  63.     hr = pIStream->Read( (void *)&size, sizeof( size ), NULL );
  64.     if( FAILED(hr) )
  65.         return hr;
  66.  
  67.     if( size != 0 )
  68.         hr = pIStream->Read( (void *)string.GetBufferSetLength( size ), size * sizeof( char ), NULL );
  69.  
  70.     return hr;
  71. }
  72.  
  73. HRESULT ReadFromStream( LPSTREAM pIStream, BITMAPINFOHEADER** ppDib )
  74. {
  75.     HRESULT hr;
  76.     HGLOBAL hMemory;
  77.     unsigned long size;
  78.     void* pVoid;
  79.     
  80.     hr = pIStream->Read( (void *)&size, sizeof( size ), NULL );
  81.     if( FAILED(hr) )
  82.         return hr;
  83.     
  84.     if( size != 0 )
  85.     {
  86.         hMemory = GlobalAllocPtr( GMEM_MOVEABLE|GMEM_DDESHARE, (DWORD)size );
  87.         if( hMemory == NULL )
  88.             return STG_E_INSUFFICIENTMEMORY;
  89.         
  90.         pVoid = GlobalLock( hMemory );
  91.  
  92.         hr = pIStream->Read( (void *)pVoid, size, NULL );
  93.  
  94.         if( FAILED(hr) )
  95.             GlobalFree( hMemory );
  96.         else
  97.             *ppDib = (BITMAPINFOHEADER*)pVoid;
  98.     }
  99.     else
  100.         *ppDib = NULL;
  101.  
  102.     return hr;
  103. }
  104.  
  105. HRESULT ReadFromStream( LPSTREAM pIStream, CSize& cSz )
  106. {
  107.     HRESULT hr;
  108.     SIZE sz;
  109.     
  110.     hr = pIStream->Read( (void *)&sz, sizeof( SIZE ), NULL );
  111.  
  112.     cSz = sz;
  113.  
  114.     return hr;
  115. }
  116.  
  117. HRESULT ReadFromStream( LPSTREAM pIStream, int* iInteger )
  118. {
  119.     return pIStream->Read( (void *)iInteger, sizeof( int ), NULL );
  120. }
  121.  
  122. HRESULT ReadFromStream( LPSTREAM pIStream, float* fFloat )
  123. {
  124.     return pIStream->Read( (void *)fFloat, sizeof( float ), NULL );
  125. }
  126.  
  127. HRESULT ReadFromStream( LPSTREAM pIStream, SPHERE_POINT* sPoint )
  128. {
  129.     return pIStream->Read( (void *)sPoint, sizeof( SPHERE_POINT ), NULL );
  130. }
  131.  
  132. HRESULT ReadFromStream( LPSTREAM pIStream, DWORD* dWord )
  133. {
  134.     return pIStream->Read( (void *)dWord, sizeof( DWORD ), NULL );
  135. }
  136.  
  137. HRESULT WriteToStream( LPSTREAM pIStream, CString& string )
  138. {
  139.     HRESULT hr;
  140.     unsigned long size;
  141.     
  142.     size = string.GetLength();
  143.     
  144.     hr = pIStream->Write( (void *)&size, sizeof( size ), NULL );
  145.     if( FAILED(hr) )
  146.         return hr;
  147.  
  148.     if( size != 0 )
  149.         hr = pIStream->Write( (void *)string.GetBuffer( size ), size * sizeof( char ), NULL );
  150.  
  151.     return hr;
  152. }
  153.  
  154. HRESULT WriteToStream( LPSTREAM pIStream, BITMAPINFOHEADER* pDib )
  155. {
  156.     HRESULT hr;
  157.     unsigned long size;
  158.     
  159.     if( pDib != NULL )
  160.         size = DibSize(pDib);
  161.     else
  162.         size = 0;
  163.     
  164.     hr = pIStream->Write( (void *)&size, sizeof( size ), NULL );
  165.     if( FAILED(hr) )
  166.         return hr;
  167.  
  168.     if( size != 0 )
  169.         hr = pIStream->Write( (void *)pDib, size, NULL );
  170.  
  171.     return hr;
  172. }
  173.  
  174. HRESULT WriteToStream( LPSTREAM pIStream, CSize& cSz )
  175. {
  176.     SIZE sz;
  177.     
  178.     sz.cx = cSz.cx;
  179.     sz.cy = cSz.cy;
  180.  
  181.     return pIStream->Write( (void *)&sz, sizeof( SIZE ), NULL );
  182. }
  183.  
  184. HRESULT WriteToStream( LPSTREAM pIStream, int iInteger )
  185. {
  186.     return pIStream->Write( (void *)&iInteger, sizeof( int ), NULL );
  187. }
  188.  
  189. HRESULT WriteToStream( LPSTREAM pIStream, float fFloat )
  190. {
  191.     return pIStream->Write( (void *)&fFloat, sizeof( float ), NULL );
  192. }
  193.  
  194. HRESULT WriteToStream( LPSTREAM pIStream, SPHERE_POINT* sPoint )
  195. {
  196.     return pIStream->Write( (void *)sPoint, sizeof( SPHERE_POINT ), NULL );
  197. }
  198.  
  199. HRESULT WriteToStream( LPSTREAM pIStream, DWORD* dWord )
  200. {
  201.     return pIStream->Write( (void *)dWord, sizeof( DWORD ), NULL );
  202. }
  203.  
  204.