Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a COM object's data members from a property page

Status
Not open for further replies.

yerfdog7

Technical User
Sep 6, 2002
10
US

I've created a COM object to control a variety of cameras. Each camera has common functionality (ICamera). However, each also has additional data for internal use. This data is encapsulated within the camera objects, except that it must be set by the user. Therefore, each camera has a unique property page which allows the user to modify the internal data.

The problem is that the ATL property page must be initialized in the WM_INITDIALOG handler. Therefore, it needs access to the internal data.

I can access the common data through the ICamera interface (by QI'ing on m_ppUnk[0]). This, however, does not give access to the unique properties of the camera, because those are not specified in the ICamera interface.

The following is a code example. First, the partial ICamera class in blue. Then, the property page's WM_INITDIALOG handler in green.

class ATL_NO_VTABLE CCamera :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<ICamera, &IID_ICamera, &LIBID_ICameraLib>,
public IPersistStreamInitImpl<CCamera>,
public IPersistStorageImpl<CCamera>,
public ISpecifyPropertyPagesImpl<CCamera>,
public CComCoClass<CCamera, &CLSID_Camera>,
public IPersistPropertyBagImpl<CCamera>,
public ISupportErrorInfo,
public CComControl<CCamera>
{
public:
CCamera();
.
.
BEGIN_PROP_MAP(CCamera)
PROP_ENTRY(&quot;Exposure&quot;, 5, CLSID_NULL)
PROP_PAGE(CLSID_SetupPage)
PROP_DATA_ENTRY(&quot;Mode&quot;, m_iCurPMode, VT_I2)
END_PROP_MAP()

public:
// this is the common interface
STDMETHOD(get_Exposure)(/*[out, retval]*/ float *pVal);
STDMETHOD(put_Exposure)(/*[in]*/ float newVal);

short m_iCurPMode; // this is the internal data

};


LRESULT CSetupPage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
// Try to load values from camera into property page
//
CComPtr<ICamera> pCamera;
m_ppUnk[0]->QueryInterface (IID_ICamera,
reinterpret_cast<void**>(&pCamera));

float f = 0.0f;

// can access Exposure because it's part of ICamera
if (SUCCEEDED (pCamera->get_Exposure (&f)))
SetEdit (IDC_EXP, &quot;%f&quot;, f); // sets text of an edit box

// ERROR: can't access internal data member m_iCurPMode
// because it's not part of the interface definition
SetEdit (IDC_CUR_MODE, &quot;%d&quot;, pCamera->m_iCurPMode);

return 0;
}


How do I set up text in IDC_CUR_MODE if I can't access m_iCurPMode? I cannot add to the common camera interface. And I was hoping to find a better solution than adding a separate, camera-specific interface to the CCamera object.

Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top