Привет всем!
Пишу ActiveX. Необходимо динамически сформировать выпадающий список для свойства ActiveX.
Вроде все делал как в MSDN. ComboBox в Properties window появляеться, но тока он пустой. Вот код:
//Свойство Prop
__interface IAFFF : public IDispatch
{
[propget, id(1), helpstring("property Prop")] HRESULT Prop([out, retval] LONG* pVal);
[propput, id(1), helpstring("property Prop")] HRESULT Prop([in] LONG newVal);
};
....
//Данные храним в переменной
long m_prop;
BEGIN_PROP_MAP(AFFF)
PROP_DATA_ENTRY("Prop", m_prop, VT_I4)
END_PROP_MAP()
....
// Собственно сами методы IPerPropertyBrowsingImpl
STDMETHODIMP AFFF::GetPredefinedStrings(DISPID dispid, CALPOLESTR * lpcaStringsOut, CADWORD * lpcaCookiesOut)
{
USES_CONVERSION;
HRESULT hResult = S_FALSE;
// we should have gotten two pointers if we didn't
if((lpcaStringsOut == NULL) || (lpcaCookiesOut == NULL))
{
// we are out of here
return E_POINTER;
}
// if this is the property that we are looking for
if(dispid == 1)
{
char* szvalue1 = "value_1";
char* szvalue2 = "value_2";
ULONG ivalue1 = 0;
ULONG ivalue2 = 1;
ULONG ulElems = 2;
// allocate the memory for our string array
lpcaStringsOut->pElems = (LPOLESTR *) ::CoTaskMemAlloc( sizeof(LPOLESTR) * ulElems);
// if we couldn't allocate the memory
if(lpcaStringsOut->pElems == NULL)
// were out of here
return E_OUTOFMEMORY;
// allocate the memory for our cookie array
lpcaCookiesOut->pElems = (DWORD*) ::CoTaskMemAlloc(sizeof(DWORD*) * ulElems);
// if we couldn't allocate the memory
if (lpcaCookiesOut->pElems == NULL)
{
// free the string array
::CoTaskMemFree(lpcaStringsOut->pElems);
// exit the function
return E_OUTOFMEMORY;
}
// store the number of elements in each array
lpcaStringsOut->cElems = ulElems;
lpcaCookiesOut->cElems = ulElems;
// allocate the strings
lpcaStringsOut->pElems[0] = ATLA2WHELPER((LPWSTR)::CoTaskMemAlloc((lstrlen(szvalue1) + 1) * 2),
szvalue1, lstrlen(szvalue1) + 1);
lpcaStringsOut->pElems[1] = ATLA2WHELPER((LPWSTR)::CoTaskMemAlloc( (lstrlen(szvalue2) + 1) * 2),
szvalue2, lstrlen(szvalue2) + 1);
// assign the cookie value
lpcaCookiesOut->pElems[0] = ivalue1;
lpcaCookiesOut->pElems[1] = ivalue2;
hResult = S_OK;
}
return hResult;
}
STDMETHODIMP AFFF::GetPredefinedValue(DISPID dispid, DWORD dwCookie, VARIANT* lpvarOut)
{
BOOL bResult = FALSE;
// which property is it
switch(dispid)
{
case 1:
// clear the variant
::VariantInit(lpvarOut);
// set the type to a long
lpvarOut->vt = VT_I4;
// set the value to the value that was stored with the string
lpvarOut->lVal = dwCookie;
// set the return value
bResult = TRUE;
char buffer[23];
itoa(dwCookie, buffer, 10);
MessageBox(buffer);
break;
}
return bResult;
}
STDMETHODIMP AFFF::GetDisplayString(DISPID dispid, BSTR* lpbstr)
{
HRESULT hResult = S_FALSE;
// which property is it
if (dispid == 1)
{
if (m_prop == 0)
*lpbstr = ::SysAllocString(T2OLE("value_1"));
if (m_prop == 1)
*lpbstr = ::SysAllocString(T2OLE("value_2"));
hResult = S_OK;
}
return hResult;
}
Что я не так делаю?