CDllSample Example
The CSampleInfo Class includes a set of reader/writers to negotiate with HWAccess I/O access to the hardware ports. The class has all the logic required to perform calculations to the data retrieved, data formatting, buffer storage and the necessary error handling. The class encapsulates the low-level functionality of the library. Within dllsample.h the definition for the class derived by the CCommonDll is as follows:
class CSampleDll : public CCommonDll { DECLARE_DYNCREATE(CSampleDll) private: UINT m_nTotalEntries; protected: CString m_cMenuName; // Construction
public: CSampleDll(); virtual ~CSampleDll(); // Attributes public: // Define a watch structure to use for I/O watches struct tagWatchIO { UDWORD dwAddress; UBYTE btAccess; }; typedef tagWatchIO SWATCHIO; typedef SWATCHIO * PWATCHIO; CCLinkedList<SWATCHIO> m_stcWatchIO; // Define an imformation class to acquire h/w info
CSampleInfo m_CSampleInfo; // Define the configuration dialog PSAMPLEDLG m_pDlg; // Define the Active Controls dialog PACTIVEDLG m_pActiveDlg;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSampleDll)
//}}AFX_VIRTUAL
BOOL CopyNextSegment(PVIEWSHOW pShow);
BOOL CopyNextUpdate(PVIEWDATA pShow);
//{{AFX_MSG(CSampleDll)
// Message Handlers to handle events send by the main application
// These are the AM_ Type Messages
afx_msg void OnWatchToggle(UINT nID);
afx_msg void OnRefresh();
afx_msg LRESULT OnDispatchInit( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnDispatchEnd( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnViewShowSize( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnViewShow( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnViewColorChange( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnPaneInit( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnPaneTrackMenu( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnActiveInit( WPARAM wParam, LPARAM lParam );
afx_msg LRESULT OnDialogInit( WPARAM wParam, LPARAM lParam );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
typedef CSampleDll * PSAMPLEAPP;
There is a list of AM type message handlers within the class definition and are briefly described here.
OnWatchToggle handler is invoked when the user changes the state on one of the watches of this DLL. The state of the watch is kept in this case within the DLL as well as the main application. The handler records the current watch state and indirectly informs a separate thread that monitors the watches of the update.
OnRefresh handler is invoked when the user clicks the refresh button initiating a scan of the ports and memory. The handler initiates a separate thread to perform the scan. Upon completion the data are formatted and stored in a buffer. Most of the handling for this process is done within the CSampleInfo class.
OnDispatchInit handler is invoked by HWAcces right after the library is loaded. The library may perform initialization of its resources at this point. Note the active controls must be initialized under the ActiveInit.
OnDispatchEnd handler is invoked when the application terminates or the library is unloaded via the remove library option. The library will not receive further messages from HWAccess. Dispatching messages to HWAccess will have no effect as the handles and communication channels are suspended. The library should terminate secondary threads and release resources at this point. The O/S will also call the library with the process detach when HWAccess invokes the FreeLibrary function.
OnViewShowSize is called when the main application requests the buffer size of the library. The DLL should return the size of the item the call is refer to and not the entire buffer size.
OnViewShow is called when the main application requires the DLL formatted data. It is typically invoked when the user selects a tree item in the parameters pane. Indirectly can be invoked by the library itself if the later dispatches an LM_VIEW_SHOW message.
OnViewColorChange is called when the user changes the main view colors. If the DLL deployed active controls this is the place to change the colors for them.
OnPaneInit is invoked once right after the OnActiveInit. The DLL must register at least one entry for the parameters pane at this point. It is also recommended to begint H/W process and create secondary threads when this call is invoked.
OnPaneTrackMenu is invoked when the user does a right click on the parameters pane. The DLL may handle this message and create a popup menu for the user.
OnActiveInit is invoked after the OnDispatchInit. The main application passes a handle to the window that involves the active controls. If the library processes this message it should create the active controls dialog.
OnDialogInit is invoked when the user selects the main menu options. Like the OnActiveInit if the library processes this message it should create a dialog to display its static options.

