Further Extensions: Module State Issues
NOTE >> We’ve only exported two properties. Extensions are left to the developer.
You can get a good idea of how to go about extending this by examining the method we’ve provided, SetValue():
STDMETHODIMP Cmychart::SetValue(VARIANTARG iDataPoint,
CString s;
//quick & dirty...assume all variant arguments vt to be integer....
m_Graph.SetValue(iDataPoint.iVal, iGroup.iVal, iValue.iVal);
s.Format(_T("(%d, %d)"), iDataPoint.iVal, iGroup.iVal);
m_Graph.GetSafeData(iDataPoint.iVal, iGroup.iVal)->SetAnnotation(s);
return S_OK;
Of course, this is rudimentary, but it does illustrate an important point. Note the call to AFX_MANAGE_STATE(). As explained below, this is necessary in any routine that is callable externally. Other methods may be defined on the Imychart interface to make functionality in the base Objective Chart control accessible through the ActiveX control you are developing.
The Objective Chart libraries require initialization before they can be used. During this process, resources are allocated and made available to the module that uses them. It is important that any such resources be available only to the module and not to the application. If such resources were to live in the application, several conflicts could arise.
Consider a case where two ATL-based DLLs link in Objective Chart. Assume that the first performs control registration. The second is then loaded. Both work fine. Then let us assume that the first control gets terminated, while the rest of the application continues to run. Like any good control, the first control cleans up after itself, un-registering the class. When the second control tries to create a control of this class, it fails.
Objective Chart is completely aware of these issues and can be used freely inside different ATL modules. Remember to call AFX_MANAGE_STATE(AfxGetStaticModuleState()) when you export functions that will be called from other modules. Non-module state-aware MFC controls will fail under these situations.
In this chapter, we have provided guidelines and working code, as well as code generation helpers, for better ATL compatibility with Objective Chart. Please contact us if you encounter problems with this support or if there are other features that you would like to see implemented.