/////////////////////////////////////////////////////////////////////////////
// CPrivateProfile
-STDMETHODIMP CPrivateProfile::InterfaceSupportsErrorInfo(REFIID riid)
-{
- static const IID* arr[] =
- {
- &IID_IPrivateProfile
- };
- for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
- {
- if (IsEqualGUID(*arr[i],riid))
- return S_OK;
- }
- return S_FALSE;
-}
-
STDMETHODIMP CPrivateProfile::get_ProfilePath(BSTR *pVal)
{
- *pVal = m_bstr_profilepath.copy();
- return S_OK;
+ return m_bstr_profilepath.CopyTo(pVal);
}
STDMETHODIMP CPrivateProfile::put_ProfilePath(BSTR newVal)
return S_OK;
}
-STDMETHODIMP CPrivateProfile::OpenSection(VARIANT text,VARIANT* pVal)
+STDMETHODIMP CPrivateProfile::OpenSection(VARIANT text, VARIANT* pVal)
{
::VariantInit(pVal);
CComVariant varText;
- if(varText.ChangeType(VT_BSTR,&text) != S_OK){
- return DISP_E_TYPEMISMATCH;
+
+ HRESULT hr;
+ if (FAILED(hr = varText.ChangeType(VT_BSTR, &text))) {
+ return hr;
}
- if(m_bstr_profilepath.length() <= 0){
- ErrorInfo(IDS_ERR_PROFILEPATH);
- return DISP_E_EXCEPTION;
+
+ if (m_bstr_profilepath.Length() <= 0) {
+ return Error(IDS_ERR_PROFILEPATH);
}
+
CComObject<CProfileSection>* pSection = NULL;
- pSection->CreateInstance(&pSection);
+ if (FAILED(hr = CComObject<CProfileSection>::CreateInstance(&pSection))) {
+ return hr;
+ }
ATLASSERT(pSection);
- WideCharToMultiByte(GetACP(),0,m_bstr_profilepath,-1,pSection->m_szProfilePath,MAX_PATH,NULL,NULL);
- WideCharToMultiByte(GetACP(),0,varText.bstrVal ,-1,pSection->m_szSectionName,MAX_PATH,NULL,NULL);
- IUnknown* pUnk = NULL;
- pSection->QueryInterface(IID_IUnknown,(void**)&pUnk);
+
+ CComPtr<IUnknown> pUnk = NULL;
+ if (FAILED(hr = pSection->QueryInterface(&pUnk))) {
+ delete pSection;
+ return hr;
+ }
ATLASSERT(pUnk);
- pVal->vt = VT_UNKNOWN;
- pVal->punkVal = pUnk;
+
+ pSection->m_szProfilePath = m_bstr_profilepath;
+ pSection->m_szSectionName = varText.bstrVal;
+
+ pVal->vt = VT_UNKNOWN;
+ pVal->punkVal = pUnk.Detach();
return S_OK;
}