There are many limitations in DAO multi-threaded processing, So I designed such a class to use DAO's forced calling through GUI threads. A gui message queue is used in the class. All calls to CMultiDAORecordset are forced to use AfxGetThread () to check the current thread. The GUI thread pointer is placed at the beginning of the InitInstance. If the introduced call request is not running in the GUI thread, CMultiDAORecordSet will send a WM_MULTIDAOMESSAGE message to AfxGetMainWnd () (IN Mainfrm. cpp ). When Mainfrm receives the message, the thread will run again. At this time, the message has been accepted, and the basic class CDaoRecordset will be called. Therefore, your class is inherited from CMultiDAORecordset, rather than CDaoRecordset, as shown below:
Class CMySet: public CMultiDaoRecordSet
In the corresponding CPP file, you should also change the following:
IMPLEMENT_DYNAMIC (CMySet, CMultiDaoRecordSet)
CMySet: CMySet (CDaoDatabase * pdb): CMultiDaoRecordSet (pdb)
To process the received WM_MULTIDAOMESSAGE, the following code should also be added to MainFrm:
In the MainFrm. h file, add:
# Ifdef MAINFRAME_CPP
UINT WM_MULTIDAOMESSAGE = RegisterWindowMessage ("WM_MULTIDAOMESSAGE ");
# Else
Extern UINT WM_MULTIDAOMESSAGE;
# Endif
Afx_msg LONG OnMultiDaoMessage (UINT uParam, LONG lParam );
In the MainFrm. cpp file, add:
# Define MAINFRAME_CPP
# Include "MutliDaoRecordset. h"
// Added to the message map
BEGIN_MESSAGE_MAP (CMainFrame, CMDIFrameWnd)
// {AFX_MSG_MAP (CMainFrame)
ON_REGISTERED_MESSAGE (WM_MULTIDAOMESSAGE, OnMultiDaoMessage)
END_MESSAGE_MAP ()
// This function added
LONG CMainFrame: OnMultiDaoMessage (UINT uParam, LONG lParam)
{
// Jtm
// Based on switch, perform operation...
CMultiDaoRecordSet * pSet = (CMultiDaoRecordSet *) lParam;
LONG lRet = 0;
CString cRet = "";
COleVariant cVar;