Further Extensions: Module State Issues
NOTE >> We’ve only exported two properties. We have not exported any of the Objective Edit control’s language syntax support. These extensions are left to the developer.
You can get a good idea of how to go about extending this by examining the code property retrieval method we’ve provided, get_Text():
STDMETHODIMP Cmyedit::get_Text(BSTR * pstrText)
CString contents;
return S_OK;
Of course, this is rudimentary, but it does illustrate two important points:
*As explained below, the call to AFX_MANAGE_STATE() is necessary in any routine that is callable externally.
*Note the invocation of the Objective Edit control method GetTextBlock()— called on the member variable m_wndClassImpl. This is the actual instance of the class SECEditCtrl provided by “wrapper” classes in header file sectxmacs.h. See this file for implementation details; in general this member variable may be used to access any SECEditCtrl class provided functionality. So this method can be modified (for example, to access the language syntax support functionality as described) and other methods may be defined on the Imyedit interface to make functionality in the base Objective Edit control accessible through the ActiveX control you are developing.
The Objective Edit 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 Edit. 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 Edit is aware of these issues and can be used freely inside different ATL modules. Remember to call AFX_MANAGE_STATE(AfxGetStaticModuleState()) when exporting functions that will be called from other modules. Non-module state-aware MFC controls will fail under these situations.
NOTE >> If you need help implementing the ATL functionality, contact Perforce Professional Services.