home *** CD-ROM | disk | FTP | other *** search
- /*++
-
- (C) Copyright 1995 - 1999 Microsoft Corporation. All rights reserved.
-
- Module Name:
-
- cresprop.cpp
-
- Abstract:
-
- Implements the CEnumResourceJAVAPROPERTY class.
-
- --*/
-
- #pragma hdrstop
-
- #include "jview.h"
- #include "cresprop.hpp"
-
- CEnumResourceJAVAPROPERTY::CEnumResourceJAVAPROPERTY(
- LPRESOURCEJAVAPROPERTY pProperties, ULONG cProperties)
- {
- m_cRef = 1;
-
- m_pProperties = pProperties;
- m_cProperties = cProperties;
- m_current = 0;
- }
-
- STDMETHODIMP
- CEnumResourceJAVAPROPERTY::QueryInterface(REFIID riid, LPVOID *ppvObj)
- {
- HRESULT hr;
-
- if (riid == IID_IEnumJAVAPROPERTY || riid == IID_IUnknown) {
- *ppvObj = (LPENUMJAVAPROPERTY) this;
- m_cRef++;
- hr = S_OK;
- } else {
- *ppvObj = NULL;
- hr = E_NOINTERFACE;
- }
-
- return hr;
- }
-
- STDMETHODIMP_(ULONG)
- CEnumResourceJAVAPROPERTY::AddRef()
- {
- m_cRef++;
-
- return m_cRef;
- }
-
- STDMETHODIMP_(ULONG)
- CEnumResourceJAVAPROPERTY::Release()
- {
- m_cRef--;
-
- if (m_cRef > 0)
- return m_cRef;
-
- delete this;
- return 0;
- }
-
- STDMETHODIMP
- CEnumResourceJAVAPROPERTY::Next(ULONG celt, LPJAVAPROPERTY rgelt, ULONG
- *pceltFetched)
- {
- HRESULT hr;
- ULONG celtFetched;
- char buffer[256];
- int cchUnicode;
-
- hr = S_OK;
- celtFetched = 0;
-
- while (hr == S_OK && celtFetched < celt) {
-
- if (m_current >= m_cProperties) {
- hr = S_FALSE;
- break;
- }
-
- if (LoadString(GetModuleHandle(NULL), m_pProperties[m_current].ValueID,
- buffer, sizeof(buffer)) > 0) {
-
- cchUnicode = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer, -1,
- NULL, 0);
-
- if (cchUnicode > 0) {
-
- rgelt->pszValue = (LPOLESTR) CoTaskMemAlloc(cchUnicode *
- sizeof(OLECHAR));
-
- if (rgelt->pszValue != NULL) {
- MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer, -1,
- rgelt->pszValue, cchUnicode);
- } else {
- hr = E_OUTOFMEMORY;
- }
-
- } else {
- hr = E_UNEXPECTED;
- }
-
- } else {
- hr = E_FAIL;
- }
-
- if (hr == S_OK) {
-
- rgelt->pszKey = (LPOLESTR)
- CoTaskMemAlloc((lstrlenW(m_pProperties[m_current].pszKey) + 1) *
- sizeof(OLECHAR));
-
- if (rgelt->pszKey != NULL) {
-
- wcscpy(rgelt->pszKey, m_pProperties[m_current].pszKey);
-
- rgelt++;
- m_current++;
- celtFetched++;
-
- } else {
- CoTaskMemFree(rgelt->pszValue);
- hr = E_OUTOFMEMORY;
- }
- }
- }
-
- if (pceltFetched != NULL)
- *pceltFetched = celtFetched;
-
- return hr;
- }
-
- STDMETHODIMP
- CEnumResourceJAVAPROPERTY::Skip(ULONG celt)
- {
- HRESULT hr;
-
- if (m_current + celt <= m_cProperties) {
- m_current += celt;
- hr = S_OK;
- } else {
- m_current = m_cProperties;
- hr = S_FALSE;
- }
-
- return hr;
- }
-
- STDMETHODIMP
- CEnumResourceJAVAPROPERTY::Reset()
- {
- m_current = 0;
- return S_OK;
- }
-
- STDMETHODIMP
- CEnumResourceJAVAPROPERTY::Clone(LPENUMJAVAPROPERTY *ppenum)
- {
- HRESULT hr;
- CEnumResourceJAVAPROPERTY *pClone;
-
- pClone = new CEnumResourceJAVAPROPERTY(m_pProperties, m_cProperties);
-
- if (pClone != NULL) {
- pClone->m_current = m_current;
- *ppenum = (LPENUMJAVAPROPERTY) pClone;
- hr = S_OK;
- } else {
- *ppenum = NULL;
- hr = E_OUTOFMEMORY;
- }
-
- return hr;
- }
-