Getting and Setting Properties of a Dialog Created Control in COM and OLE

OK, I recently had a really hard time getting and setting the properties of an ActiveX control in C++.  I'm just writing a quick post on how this works because I had a heck of a time finding the right resources for this.  What I had done was dragged and dropped a control from the toolbox onto a dialog application.  After dropping the component onto the application, I wanted, inside of code and not within the resource editor, to alter a few of the properties for the control.  For some ungodly reason, in C++, the project wizard does not create a reference to the ActiveX control to enable programmers to easily call methods on the control.  What I had to do was the following:

1.) Get a client reference to the control that you will be getting/setting properties on.

CComPtr<IInkPicture> ip;

2.) Now, use that control to retrieve the DISPID for the property you will be getting/setting.

// for dispid retrieval
DISPID dispid = 0;
OLECHAR FAR* szMember = OLESTR("EditingMode");
ip->GetIDsOfNames(IID_IInkPicture, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &dispid);

3.) Retrieve the CWnd (Control Window) for the control by using its control identifier (right-clicking the control in your dialog editor will get you to its properties).

CWnd* pInkWnd = NULL;
pInkWnd = this->GetDlgItem(IDC_INKPICTURE1);

4.) Set the property. Note that you must pass the property type in the second parameter for CWnd::SetProperty. The types of properties are in the remarks for the COleDispatchDriver::InvokeHelper function on MSDN.

// I'm assuming that using a short for setting the property will work fine here
pInkWnd->SetProperty(dispid, VT_I2, mode);

There you have it. Getting and setting properties in dialog applications built using MFC.