bool __fastcall IsWow64()
{
//为True时,则是32位的程序运行在64位的系统上,为False时,则是32位程序运行在32位系统上或64位程序运行在64位系统上!
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE,PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL bIsWow64=FALSE;
fnIsWow64Process=(LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(L"kernel32"),"IsWow64Process");
if(fnIsWow64Process!=NULL)
{
if(!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
bIsWow64=FALSE;
}
}
if(bIsWow64==FALSE)
return false;
else
return true;
}
//---------------------------------------------------------------------------
UnicodeString __fastcall GetSQLServerNativeClientDll()
{
UnicodeString Key,Value,DllName=L"sqlsrv32.dll";
TStringList *List=new TStringList();
TRegistry *Registry = new TRegistry();
Registry->Access=KEY_QUERY_VALUE|KEY_READ;
Registry->RootKey=HKEY_LOCAL_MACHINE;
if(IsWow64())
Key="SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI";
else
Key="SOFTWARE\ODBC\ODBCINST.INI";
if(Registry->KeyExists(Key))
{
//ShowMessage(Key);
Registry->OpenKey(Key,false);
Registry->GetKeyNames(List);
for(int i=List->Count;i>0;i--)
{
Value=List->Strings[i-1];
//ShowMessage(Value); //
if(Value.Pos(L"SQL Server Native Client")>0||Value.Pos(L"SQL Native Client")>0)
{
Registry->OpenKey(Value,false);
DllName=Registry->ReadString(L"Driver");
break;
}
}
}
Registry->CloseKey();
delete Registry;
delete List;
//ShowMessage(DllName);
return DllName;
}