k;
case MultiDaoMove:
pSet->Move(*(LONG *)pSet->pParam1);
break;
case MultiDaoFindNext:
lRet = (LONG)pSet->FindNext(*(LPCTSTR *)pSet->pParam1);
break;
case MultiDaoFindPrev:
lRet = (LONG)pSet->FindPrev(*(LPCTSTR*)pSet->pParam1);
break;
case MultiDaoFindFirst:
lRet = (LONG)pSet->FindFirst(*(LPCTSTR *)pSet->pParam1);
break;
case MultiDaoFindLast:
lRet = (LONG)pSet->FindLast(*(LPCTSTR *)pSet->pParam1);
break;
case MultiDaoFind:
lRet = (LONG)pSet->Find(*(LONG *)pSet->pParam1, *(LPCTSTR*)pSet->pParam2);
break;
case MultiDaoGetBookmark:
cVar = pSet->GetBookmark();
lRet = (LONG)&cVar;
break;
case MultiDaoSetBookmark:
pSet->SetBookmark(*(COleVariant*)pSet->pParam1);
break;
case MultiDaoAddNew:
pSet->AddNew();
break;
case MultiDaoEdit:
pSet->Edit();
break;
case MultiDaoUpdate:
pSet->Update();
break;
case MultiDaoDelete:
pSet->Delete();
break;
case MultiDaoCancelUpdate:
pSet->CancelUpdate();
break;
case MultiDaoRequery:
pSet->Requery();
break;
}
}
catch (CDaoException *e)
{
TRACE("Database Multithread Operation Failed%s\n",
e->m_pErrorInfo->m_strDescription);
}
return lRet;
}
下面的代码是加在对应的应用
程序对象的头文件中的:
public:
CWinThread *pGUIThread;
And this to the constructor in the app .cpp file:
CMyApp::CMyApp()
{
pGUIThread = AfxGetThread();
}
如果没有上面的定义的话,你的应用
程序就会出
问题。整个DAO公共函数并没有全部实现,但不管怎么样,上面的函数是保护CDaoRecordset的使用的。如果你要加个函数的话,加进去就行了,你也可以用一个对话框来显示错误信息,它们都应该在MultiDaorecordset.h中被定义。为了支持DAO多线程的类,下面的代码也应该加进去:
加在Multidaorecordset.cpp中:
// MultiDaoRecordSet.cpp : implementation file
//
#define MULTIDAORECORDSET_CPP
#include "stdafx.h"
#include "MyApp.h"
#include "MultiDaoRecordSet.h"
#include "mainfrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMultiDaoRecordSet
IMPLEMENT_DYNAMIC(CMultiDaoRecordSet, CDaoRecordset)
CMultiDaoRecordSet::CMultiDaoRecordSet(CDaoDatabase* pdb)
: CDaoRecordset(pdb)
{
//{{AFX_FIELD_INIT(CMultiDaoRecordSet)
//}}AFX_FIELD_INIT
m_nDefaultType = dbOpenDynaset;
}
//jtm
//thread safe destructor.
CMultiDaoRecordSet::~CMultiDaoRecordSet()
{
if (IsOpen())
Close();
// Clean up database if necessary
if (m_pDatabase != NULL && (m_nStatus & AFX_DAO_IMPLICIT_DB))
{
m_pDatabase->Close();
delete m_pDatabase;
m_pDatabase = NULL;
}
}
CString CMultiDaoRecordSet::GetDefaultDBName()
{
CMyApp *pApp = ((CMYApp *)AfxGetApp());
return pApp->GetDatabaseFullPath();
}
/////////////////////////////////////////////////////////////////////////////
// CMultiDaoRecordSet diagnostics
//jtm
//multi thread safe functoins
void CMultiDaoRecordSet::Open(int nOpenType, LPCTSTR lpszSQL, int nOptions)
{
CMYApp *pApp = ((CMYApp *)AfxGetApp());
if (pApp->pGUIT