| // *********************************************************
// リストボックスにAccessのテーブル一覧を追加
// 戻り値 : 成功 true, 失敗 false
// ※ Access.Application 版
// *********************************************************
#import "C:\Program Files\Common Files\system\ado\msado21.tlb" \
rename("EOF", "EOFado")
#import "C:\Program Files\Common Files\Microsoft Shared\DAO\dao360.dll" \
rename("EOF", "EOFdao")
//#import "C:\Program Files\Microsoft Office\Office\MSO9.DLL"
//#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
#import "MSACC9.OLB"
using namespace Access;
using namespace DAO;
BOOL LboxEnumAccessTable( HWND hList, int nIndex, LPCTSTR szFile )
{
if ( *szFile == 0x00 ) {
LboxListInsert( hList, nIndex, "*ERROR\tファイル名を指定して下さい" );
return false;
}
if ( !PathFileExists( szFile ) ) {
LboxListInsert( hList, nIndex, "*ERROR\tファイルが存在しません" );
return false;
}
LPTSTR lpExt;
lpExt = PathFindExtension( szFile );
if ( *lpExt != '.' ) {
LboxListInsert( hList, nIndex, "*ERROR\tMDBではありません" );
return false;
}
if( StrStrI( lpExt, "mdb" ) == NULL ) {
LboxListInsert( hList, nIndex, "*ERROR\tMDBではありません" );
return false;
}
BOOL bRet;
_bstr_t StringBuffer("");
StringBuffer.operator = (szFile);
CoInitialize(NULL);
Access::_ApplicationPtr pMDB;
DAO::DatabasePtr pDAO;
DAO::TableDefsPtr pDef;
DAO::_TableDefPtr pTable;
long i,nCount;
_variant_t nIdx;
nIdx.vt = VT_I4;
char *szBuffer;
try {
pMDB.CreateInstance(L"Access.Application");
pMDB->OpenCurrentDatabase( szFile, VARIANT_TRUE );
pDAO = pMDB->CurrentDb();
pDef = pDAO->TableDefs;
nCount = pDef->Count;
for( i = 0; i < nCount; i++ ) {
nIdx.lVal = i;
pTable = pDef->GetItem( &nIdx );
StringBuffer.operator = (pTable->Name);
szBuffer = StringBuffer.operator char * ();
LboxListInsert( hList, nIndex, szBuffer );
nIndex++;
}
pMDB->CloseCurrentDatabase();
bRet = true;
}
catch (_com_error &e)
{
LboxListInsert( hList, nIndex, e.ErrorMessage() );
bRet = false;
}
CoUninitialize();
return bRet;
}
| |