CoInitialize与CoUninitialize是一对出现;使用如下:
CoInitialize(NULL);
//组件使用代码部分
CoUninitialize();
void __fastcall CHKqq::Execute()
{
CoInitialize(NULL);
//---- Place thread code here ----
//验证注册码
// ADO连接
TADOConnection *con = new TADOConnection(NULL);
TADOQuery *aq = new TADOQuery(NULL);
TADOQuery *aq1 = new TADOQuery(NULL);
try
{
if (con->Connected)
con->Connected = false;
// 连接该MDB数据库
AnsiString s;
con->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="+
QuotedStr(s)+";User ID=Admin;Data Source="+strMdbFile+
";Mode=Share Deny None;Persist Security Info=True;Jet OLEDB:Database Password="+Form5->Dec("771866F50B9BABB42A")+
";Jet OLEDB:Engine Type=5;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
try
{
//这个可以关闭database login提示对话框
con->LoginPrompt=false;
con->Connected = true;
//
}
catch(...)
{
::MessageBox(0, TEXT("打开数据库失败!"),
TEXT("警告"), MB_OK | MB_ICONWARNING);
}
// 如果连接成功,就通过ADOQuery读取字段
if (con->Connected)
{
aq->Connection = con;
AnsiString SQLstr="select *from login";
aq->Close();
aq->SQL->Text = SQLstr;
aq1->Connection = con;
SQLstr="select *from sxsq";
aq1->Close();
aq1->SQL->Text = SQLstr;
//
aq->Open();
aq1->Open();
if(aq->RecordCount && aq1->RecordCount)
{
//取QQ号
String QQzc=aq1->FieldList->Fields[0]->Text;
String QQzctime =aq1->FieldList->Fields[1]->Text;
String QQendtime =aq1->FieldList->Fields[2]->Text; //截止时间
aq->First();
for(int i=0;i<aq->RecordCount;i++)
{
Form5->QQurl=aq->FieldList->Fields[0]->Text;
//检测有无此QQ路径并存储路径
if(!DirectoryExists(Form5->Dec(Form5->QQurl)))
{
if(Form5->Dec(Form5->QQurl).Pos(Form5->Dec(QQzc).SubString(1,Form5->Dec(QQzc).Length()-2)))
{
TDateTime FileTime=TFile::GetLastWriteTime(Form5->Dec(Form5->QQurl));
String Ltime= FormatDateTime("yyyy-mm-dd hhnnss",FileTime.CurrentDateTime()); //文件的时间
int Scz=SecondsBetween(FileTime.CurrentDateTime(),Now());
if(Scz<=300)
{
//注册成功
Form5->lbl1->Caption="注册 Q Q:"+ Form5->Dec(QQzc).SubString(1,Form5->Dec(QQzc).Length()-2);
Form5->lbl2->Caption="截止时间:"+ Form5->Dec(QQendtime);
Form1->Caption="3D扫描 V20210606 "+ Form5->lbl1->Caption+" 登陆时间:"+Ltime;
return;
}
//存储QQ路径和时间
//QQsave(QQurl,Ltime); //存储历次QQ登陆路径
}
}
aq->Next();
}
}
else
{
//ShowMessage("没有QQ注册信息!");
Form1->Caption="3D全动态扫描 V20210606 测试版" ;
Form5->QQurl="";
}
}
}
__finally
{
delete aq;
aq=NULL;
delete con;
con=NULL;
delete aq1;
aq1=NULL;
CoUninitialize();
}
}