home *** CD-ROM | disk | FTP | other *** search
- /*++
-
- Copyright (c) 1999 Microsoft Corporation
-
- Module Name:
-
- jpsplit.cpp
-
- Abstract:
-
- sample code.
- defines secondary methods and structures for splitting/parsing jexegen
- images.
-
- --*/
-
- #pragma warning(disable:4514) // "unreferenced inline function" warning
-
- #pragma warning(disable:4201) // "nameless struct/union" warning
- #include <windows.h>
- #pragma warning(default:4201) // "nameless struct/union" warning
-
- #include "jpsplit.h"
- #include "jpcommon.h"
- #include "util.h"
-
-
- inline
- HCRIDATA
- CRI_DATA_TO_HANDLE(
- const COMRegistrationInfoHeader *pCRIHeader )
- {
- return( (HCRIDATA)pCRIHeader );
- }
-
- inline
- const COMRegistrationInfoHeader *
- CRI_DATA_FROM_HANDLE(
- HCRIDATA hCRIData )
- {
- return( (const COMRegistrationInfoHeader *)hCRIData );
- }
-
-
- //------------------------------------------------------------------------------
- // methods for enumerating COM registration information (CRI) resource data
- // found in java/COM DLLs created by jexegen.
- //------------------------------------------------------------------------------
-
- // clients must call this method to obtain a handle to CRI data.
- // returns NULL on failure.
- HCRIDATA
- CRIOpenData(
- HMODULE hModule,
- WORD wCRIResourceID )
- {
- HCRIDATA hRetVal;
- HRSRC hResource;
-
- hRetVal = NULL;
-
- //
- // a CRI data handle is really just a thin wrapper around
- // the CRI data resource pointer.
- // get a pointer to the CRI data resource.
- //
-
- hResource = FindResource( hModule, MAKEINTRESOURCE( wCRIResourceID ),
- RT_RCDATA );
-
- if( hResource != NULL )
- {
- HGLOBAL hResLoaded;
-
- hResLoaded = LoadResource( hModule, hResource );
-
- if( hResLoaded != NULL )
- {
- const COMRegistrationInfoHeader *pCRIHeader;
-
- pCRIHeader = (const COMRegistrationInfoHeader *)
- LockResource( hResLoaded );
-
- // stub and CRI version should be in sync.
- ASSERT( pCRIHeader->dwVersion == JCRI_VERSION1 );
-
- if( pCRIHeader != NULL )
- {
- hRetVal = CRI_DATA_TO_HANDLE( pCRIHeader );
- }
- }
- }
-
- return hRetVal;
- }
-
- // closes the CRI data handle.
- void
- CRICloseData(
- HCRIDATA hCRIData )
- {
- UNREFERENCED_PARAMETER( hCRIData );
-
- // nothing to do.
- }
-
- // returns the number of CRI data entries that exist in the
- // given CRI data.
- ULONG
- CRIGetEntryCount(
- HCRIDATA hCRIData )
- {
- const COMRegistrationInfoHeader *pCRIHeader;
-
- pCRIHeader = CRI_DATA_FROM_HANDLE( hCRIData );
-
- return( pCRIHeader->dwClasses );
- }
-
- // enumerates all CRI data entries.
- // returns TRUE if all CRI entries were successfully enumerated.
- BOOL
- CRIEnumEntries(
- HCRIDATA hCRIData,
- CRI_ENTRY_ENUM_PROC pfcnCallback,
- void *pvExtra )
- {
- BOOL fRetVal;
- DWORD index;
- BYTE *pbDataBase;
- const COMRegistrationInfoHeader *pCRIHeader;
-
- fRetVal = TRUE;
- pCRIHeader = CRI_DATA_FROM_HANDLE( hCRIData );
- pbDataBase = (BYTE *)pCRIHeader;
-
- // enumerate over CRI entries.
- for( index = 0; fRetVal && (index < pCRIHeader->dwClasses); index++ )
- {
- LPCWSTR pcwszClassName;
- LPCWSTR pcwszProgID;
- LPCWSTR pcwszDescription;
- const COMRegistrationInfo *pCRI;
-
- pCRI = &(pCRIHeader->aRegInfo[ index ]);
-
- //
- // Get strings.
- //
- pcwszClassName = (LPCWSTR)(pbDataBase + pCRI->cbClassNameOffset);
-
- pcwszProgID = (LPCWSTR)(pbDataBase + pCRI->cbProgIDOffset);
- if( pcwszProgID == (LPCWSTR)pbDataBase)
- pcwszProgID = NULL;
-
- pcwszDescription = (LPCWSTR)(pbDataBase + pCRI->cbDescriptionOffset);
- if( pcwszDescription == (LPCWSTR)pbDataBase )
- pcwszDescription = NULL;
-
- // invoke callback.
- fRetVal = (*pfcnCallback)( index, pcwszClassName, pcwszProgID,
- pcwszDescription, pCRI->dwFlags, pCRI->guidCLSID,
- pCRI->guidTypelib, pCRI->wVerMajor, pCRI->wVerMinor, pvExtra );
- }
-
- return fRetVal;
- }
-