home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 October / CMCD1004.ISO / Software / Shareware / Utilitare / pec / pec2setup.exe / sdk / codec / template / Codec_0_EntryPoints.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-07-17  |  2.6 KB  |  111 lines

  1. #include "stdafx.h"
  2. #include "pec2codec_template.h"
  3. #include "..\pec2codecsdk.h"
  4. #include "Codec_0_EntryPoints.h"
  5.  
  6. /////////////////////////////////////////////////////////////////////////////////////
  7. //
  8. // GetCodecName
  9. //
  10. // Return the wide-characte rname of this CODEC.
  11. //
  12. //
  13.  
  14. DWORD WINAPI GetCodecName(PWCHAR pwszName, DWORD dwBufSize)
  15. {
  16.     if(dwBufSize<=wcslen(CODEC_NAME))
  17.     {
  18.         if(pwszName)
  19.         {
  20.             *pwszName=NULL;
  21.         }                
  22.         return wcslen(CODEC_NAME)+1;
  23.     }
  24.     else if(!dwBufSize)
  25.     {
  26.         return wcslen(CODEC_NAME)+1;
  27.     }
  28.     wcscpy(pwszName,CODEC_NAME);
  29.     return wcslen(pwszName);
  30. }
  31.  
  32.  
  33. DWORD WINAPI GetCodecAuthor(PWCHAR pwszAuthor, DWORD dwBufSize)
  34. {
  35.     if(dwBufSize<=wcslen(CODEC_AUTHOR))
  36.     {
  37.         if(pwszAuthor)
  38.         {
  39.             *pwszAuthor=NULL;
  40.         }                
  41.         return wcslen(CODEC_AUTHOR)+1;
  42.     }
  43.     else if(!dwBufSize)
  44.     {
  45.         return wcslen(CODEC_AUTHOR)+1;
  46.     }
  47.     wcscpy(pwszAuthor,CODEC_AUTHOR);
  48.     return wcslen(pwszAuthor);
  49. }
  50.  
  51. #define CODEC_VERSION_MAJOR 1
  52. #define CODEC_VERSION_MINOR 0
  53. #define CODEC_VERSION (CODEC_VERSION_MAJOR*100)+CODEC_VERSION_MINOR
  54.  
  55. DWORD WINAPI GetCodecVersion(PDWORD pdwSDKVersion)
  56. {
  57.     if(pdwSDKVersion)
  58.     {
  59.         *pdwSDKVersion=PEC2_CODEC_SDK_VERSION;
  60.     }
  61.     return CODEC_VERSION;
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////////////
  65. //
  66. //  Encode function
  67. //
  68. //  This codec simply copies the data from the source to the destination
  69. //  and appends a flag. It actually expands the data, which is a perfectly
  70. //  legal result no matter what the expansion size is. Of course, a compression
  71. //  function would return a buffer smaller than the original (provided compression
  72. //  succeeds).
  73. //
  74.  
  75. DWORD WINAPI Encode(LPVOID lpvSource, DWORD dwLength, LPVOID lpvDest, 
  76.                            DWORD *pdwDestSize, DWORD dwLevel, PFNCodecCallback Callback)
  77. {
  78.  
  79.     int nR=0;
  80.     PCODEC_0_HEADER pBlockHeader=(PCODEC_0_HEADER)lpvDest;
  81.     
  82.     //
  83.     // make sure destination buffer is big enough to handle our header
  84.     // expansion of the source data. If not, return PEC2_CODEC_ERROR_INSUFFICIENT_BUFFER
  85.     // so that the caller will allocate more and reinvoke.
  86.     //
  87.     if(*pdwDestSize<(dwLength+sizeof(CODEC_0_HEADER)))
  88.     {
  89.         *pdwDestSize=dwLength+sizeof(CODEC_0_HEADER);
  90.         return PEC2_CODEC_ERROR_INSUFFICIENT_BUFFER;
  91.     }
  92.     
  93.     //
  94.     // write CODEC unique signature to destination buffer
  95.     //  = for a quick runtime test of the buffer at Decode.
  96.     //
  97.  
  98.     pBlockHeader->dwDecodedSize=dwLength;
  99.     pBlockHeader->dwSignature=CODEC_0_SIGNATURE;
  100.     
  101.     //
  102.     // copy source data to destination buffer
  103.     //
  104.     memcpy(++pBlockHeader,lpvSource,dwLength);
  105.     
  106.     nR=dwLength+sizeof(CODEC_0_HEADER);
  107.  
  108.     return nR;
  109. }
  110.  
  111.