home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / COM / jexegen / stub / jpsplit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  4.1 KB  |  168 lines

  1. /*++
  2.  
  3. Copyright (c) 1999  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     jpsplit.cpp
  8.  
  9. Abstract:
  10.  
  11.     sample code.
  12.     defines secondary methods and structures for splitting/parsing jexegen
  13.      images.
  14.  
  15. --*/
  16.  
  17. #pragma warning(disable:4514)   // "unreferenced inline function" warning
  18.  
  19. #pragma warning(disable:4201)   // "nameless struct/union" warning
  20. #include <windows.h>
  21. #pragma warning(default:4201)   // "nameless struct/union" warning
  22.  
  23. #include "jpsplit.h"
  24. #include "jpcommon.h"
  25. #include "util.h"
  26.  
  27.  
  28. inline
  29. HCRIDATA
  30. CRI_DATA_TO_HANDLE(
  31.     const COMRegistrationInfoHeader *pCRIHeader )
  32. {
  33.     return( (HCRIDATA)pCRIHeader );
  34. }
  35.  
  36. inline
  37. const COMRegistrationInfoHeader *
  38. CRI_DATA_FROM_HANDLE(
  39.     HCRIDATA hCRIData )
  40. {
  41.     return( (const COMRegistrationInfoHeader *)hCRIData );
  42. }
  43.  
  44.  
  45. //------------------------------------------------------------------------------
  46. // methods for enumerating COM registration information (CRI) resource data
  47. //  found in java/COM DLLs created by jexegen.
  48. //------------------------------------------------------------------------------
  49.  
  50. // clients must call this method to obtain a handle to CRI data.
  51. // returns NULL on failure.
  52. HCRIDATA
  53. CRIOpenData(
  54.     HMODULE hModule,
  55.     WORD    wCRIResourceID )
  56. {
  57.     HCRIDATA                hRetVal;
  58.     HRSRC                   hResource;
  59.  
  60.     hRetVal = NULL;
  61.  
  62.     //
  63.     // a CRI data handle is really just a thin wrapper around
  64.     //  the CRI data resource pointer.
  65.     // get a pointer to the CRI data resource.
  66.     //
  67.  
  68.     hResource = FindResource( hModule, MAKEINTRESOURCE( wCRIResourceID ),
  69.         RT_RCDATA );
  70.  
  71.     if( hResource != NULL )
  72.     {
  73.         HGLOBAL hResLoaded;
  74.  
  75.         hResLoaded = LoadResource( hModule, hResource );
  76.  
  77.         if( hResLoaded != NULL )
  78.         {
  79.             const COMRegistrationInfoHeader *pCRIHeader;
  80.  
  81.             pCRIHeader = (const COMRegistrationInfoHeader *)
  82.                 LockResource( hResLoaded );
  83.  
  84.             // stub and CRI version should be in sync.
  85.             ASSERT( pCRIHeader->dwVersion == JCRI_VERSION1 );
  86.  
  87.             if( pCRIHeader != NULL )
  88.             {
  89.                 hRetVal = CRI_DATA_TO_HANDLE( pCRIHeader );
  90.             }
  91.         }
  92.     }
  93.  
  94.     return hRetVal;
  95. }
  96.  
  97. // closes the CRI data handle.
  98. void
  99. CRICloseData(
  100.     HCRIDATA hCRIData )
  101. {
  102.     UNREFERENCED_PARAMETER( hCRIData );
  103.  
  104.     // nothing to do.
  105. }
  106.  
  107. // returns the number of CRI data entries that exist in the
  108. //  given CRI data.
  109. ULONG
  110. CRIGetEntryCount(
  111.     HCRIDATA hCRIData )
  112. {
  113.     const COMRegistrationInfoHeader *pCRIHeader;
  114.  
  115.     pCRIHeader = CRI_DATA_FROM_HANDLE( hCRIData );
  116.  
  117.     return( pCRIHeader->dwClasses );
  118. }
  119.  
  120. // enumerates all CRI data entries.
  121. // returns TRUE if all CRI entries were successfully enumerated.
  122. BOOL
  123. CRIEnumEntries(
  124.     HCRIDATA            hCRIData,
  125.     CRI_ENTRY_ENUM_PROC pfcnCallback,
  126.     void                *pvExtra )
  127. {
  128.     BOOL    fRetVal;
  129.     DWORD   index;
  130.     BYTE    *pbDataBase;
  131.     const COMRegistrationInfoHeader *pCRIHeader;
  132.  
  133.     fRetVal = TRUE;
  134.     pCRIHeader = CRI_DATA_FROM_HANDLE( hCRIData );
  135.     pbDataBase = (BYTE *)pCRIHeader;
  136.  
  137.     // enumerate over CRI entries.
  138.     for( index = 0; fRetVal && (index < pCRIHeader->dwClasses); index++ )
  139.     {
  140.         LPCWSTR pcwszClassName;
  141.         LPCWSTR pcwszProgID;
  142.         LPCWSTR pcwszDescription;
  143.         const COMRegistrationInfo   *pCRI;
  144.  
  145.         pCRI = &(pCRIHeader->aRegInfo[ index ]);
  146.  
  147.         //
  148.         // Get strings.
  149.         //
  150.         pcwszClassName = (LPCWSTR)(pbDataBase + pCRI->cbClassNameOffset);
  151.  
  152.         pcwszProgID = (LPCWSTR)(pbDataBase + pCRI->cbProgIDOffset);
  153.         if( pcwszProgID == (LPCWSTR)pbDataBase)
  154.             pcwszProgID = NULL;
  155.  
  156.         pcwszDescription = (LPCWSTR)(pbDataBase + pCRI->cbDescriptionOffset);
  157.         if( pcwszDescription == (LPCWSTR)pbDataBase )
  158.             pcwszDescription = NULL;
  159.  
  160.         // invoke callback.
  161.         fRetVal = (*pfcnCallback)( index, pcwszClassName, pcwszProgID,
  162.             pcwszDescription, pCRI->dwFlags, pCRI->guidCLSID,
  163.             pCRI->guidTypelib, pCRI->wVerMajor, pCRI->wVerMinor, pvExtra );
  164.     }
  165.  
  166.     return fRetVal;
  167. }
  168.