我在DLL中新建了一个对话框,然后插入一个Generic类型的类ADOConn
ADOConn.H加入的代码
class ADOConn
{
public:
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
ADOConn();
virtual ~ADOConn();
void OnInitADOConn();
_RecordsetPtr& GetRecordSet(_bstr_t bstrSQL);
BOOL ExecuteSQL(_bstr_t bstrSQL);
void ExitConnect();
};
ADOConn.CPP加入的代码
void ADOConn::OnInitADOConn()
{
::CoInitialize(NULL);
try
{
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect="Provider=SQLOLEDB;Server=MY-TOMATO;Database=MY-TOMATO;uid=sa;pwd=123";
m_pConnection->Open(strConnect,"","",0);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
try
{
if(m_pConnection==NULL)
OnInitADOConn();
m_pRecordset.CreateInstance(_uuidof(Recordset));
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
return m_pRecordset;
}
BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)
{
try
{
if(m_pConnection==NULL)
OnInitADOConn();
m_pConnection->Execute(bstrSQL,NULL,adCmdText);
return true;
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
}
void ADOConn::ExitConnect()
{
if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pConnection->Close();
::CoUninitialize();
}
在StdAfx.h加入的代码
#import "C:\Program Files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
会出现error C2011: 'LockTypeEnum' : 'enum' type redefinition
error C2011: 'DataTypeEnum' : 'enum' type redefinition
error C2011: 'FieldAttributeEnum' : 'enum' type redefinition
error C2011: 'EditModeEnum' : 'enum' type redefinition
error C2011: 'RecordStatusEnum' : 'enum' type redefinition
warning C4146: unary minus operator applied to unsigned type, result still unsigned
error C2011: 'ParameterDirectionEnum' : 'enum' type redefinition
Error executing cl.exe.
1.dll - 6 error(s), 0 warning(s)的错误
而如果建在MFC EXE中就没有错误,这是为什么?哪位高手可以找点一下!