| #import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
_ConnectionPtr pCn = NULL;
_RecordsetPtr pRs = NULL;
void PrintProviderError(_ConnectionPtr pConnection)
{
ErrorPtr pErr = NULL;
if( (pConnection->Errors->Count) > 0)
{
printf("ProviderError\n");
long nCount = pConnection->Errors->Count;
for(long i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("\tError number: %x\n", pErr->Number );
printf("\tDescription: %s\n", (LPTSTR)pErr->Description);
}
}
}
void PrintComError(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// Print Com errors.
printf("ComError\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
#define ADO_MAIN(constring) \
int main( ) \
{ \
CoInitialize(NULL); \
try { \
TESTHR(pCn.CreateInstance(__uuidof(Connection))); \
_bstr_t ConString; \
ConString.operator = ( constring ); \
printf( "接続文字列は[%s]です\n", (LPTSTR)ConString ); \
pCn->Open(ConString, "", "", adConnectUnspecified); \
TESTHR(pRs.CreateInstance(__uuidof(Recordset)));
#define ADO_END pRs.Release(); pCn->Close(); pCn.Release(); } catch (_com_error &e) \
{ \
PrintProviderError(pCn); \
PrintComError(e); \
} \
CoUninitialize(); \
return 0; \
}
#define ADO_QUERY(Query) \
pRs->Open( \
Query, \
_variant_t((IDispatch *)pCn,true), \
adOpenKeyset, \
adLockOptimistic, \
adCmdText);
#define QUERY_LOOP \
while( !(pRs->EndOfFile) ) {
#define QUERY_END \
pRs->MoveNext(); \
}
#define QUERY_GET(Name,szBuff) \
{ \
_variant_t V1; \
_variant_t V2; \
V1 = Name; \
V2 = pRs->Fields->GetItem(Name)->Value; \
if ( V2.vt == VT_NULL ) { \
szBuff[0] = 0x00; \
} \
else { \
_bstr_t B1; \
B1 = V2; \
lstrcpy(szBuff, (LPTSTR)B1 ); \
} \
}
#define ADO_EXECUTE(Command) \
pCn->Execute(Command, NULL, adExecuteNoRecords);
#define ADO_CONNECT(constring) \
{ \
pCn->Close(); \
_bstr_t ConString; \
ConString.operator = ( constring ); \
printf( "接続文字列は[%s]です\n", (LPTSTR)ConString ); \
pCn->Open(ConString, "", "", adConnectUnspecified); \
}
| |