源代码:
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
no_namespace rename("EOF","EndOfFile")
#include<Ole2.h>
#include<stdio.h>
#include<conio.h>
inline void TESTHR(HRESULT x) {
if (FAILED(x)) {
_com_issue_error(x);
}
}
void CountX(void);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);
void main(){
if(FAILED(::CoInitialize(NULL)))
return;
CountX();
::CoUninitialize();
}
void CountX(){
//define ADO object pointers
_RecordsetPtr pRstEmployee=NULL;
//define other variables
HRESULT hr=S_OK;
_variant_t Index;
Index.vt=VT_I2;
int j=0;
_bstr_t strCnn("Provider=SQLOLEDB;Data Source=srv;"
"Initial Catalog=Pubs;User Id=system;Password=123456;");
try{
//open recordset with data from employee table
TESTHR(pRstEmployee.CreateInstance(_uuidof(Recordset)));
pRstEmployee->Open("Employee",strCnn,adOpenForwardOnly,
adLockReadOnly,adCmdTable);
//print information about fields collection
printf("\n%d Fields in Employee\n",pRstEmployee->Fields->Count);
for(int intLoop=0;intLoop<=(pRstEmployee->Fields->Count-1);intLoop++){
Index.iVal=intLoop;
printf(" %s\n",(LPSTR) pRstEmployee->Fields->GetItem(Index)->Name);
}
//print information about properties collection
printf("\n%d Properties in Employee\n",pRstEmployee->Properties->Count);
for(int intLoop=0;intLoop<=(pRstEmployee->Properties->Count-1);intLoop++){
j++;
Index.iVal=intLoop;
printf(" %s\n",(LPSTR) pRstEmployee->Properties->GetItem(Index)->Name);
if(((j%23)==0)||(intLoop==11)){
printf("\nPress any key to continue...");
getch();
//clear the screen for the next display
system("cls");
j=0;
}
}
//clean up object before exit
pRstEmployee->Close();
}
catch(_com_error &e){
//nodify user of any errors that result from executing the query
_variant_t vtConnect=pRstEmployee->GetActiveConnection();
switch(vtConnect.vt){
case VT_BSTR:
PrintComError(e);
break;
case VT_DISPATCH:
PrintProviderError(vtConnect);
break;
default:
printf("Errors occured");
break;
}
}
}
void PrintProviderError(_ConnectionPtr pConnection){
ErrorPtr pErr=NULL;
if((pConnection->Errors->Count)>0){
long nCount=pConnection->Errors->Count;
for(long i=0;i<nCount;i++){
pErr=pConnection->Errors->GetItem(i);
printf("Error number:%x\t%s\n",pErr->Number,pErr->Description);
}
}
}
void PrintComError(_com_error &e){
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("Error\n");
printf("\tCode=%081x\n",e.Error());
printf("tCode meaning=%s\n",e.ErrorMessage());
printf("\tSource=%s\n",(LPCSTR) bstrSource);
printf("\tDescription=%s\n",(LPCSTR) bstrDescription);
}
调试结果:
“ado.exe”: 已加载“C:\Users\Administrator\Desktop\ado\Debug\ado.exe”,已加载符号。
“ado.exe”: 已加载“C:\Windows\SysWOW64\ntdll.dll”,已加载符号(去除源信息)。
“ado.exe”: 已加载“C:\Windows\SysWOW64\kernel32.dll”,已加载符号(去除源信息)。
“ado.exe”: 已加载“C:\Windows\SysWOW64\KernelBase.dll”,已加载符号(去除源信息)。
“ado.exe”: 已加载“C:\Windows\SysWOW64\ole32.dll”,已加载符号。
“ado.exe”: 已加载“C:\Windows\SysWOW64\ucrtbase.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\rpcrt4.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\combase.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\gdi32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\win32u.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\gdi32full.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msvcp_win.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\user32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\oleaut32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msvcr100d.dll”,已加载符号。
“ado.exe”: 已加载“C:\Windows\SysWOW64\imm32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\kernel.appcore.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msvcrt.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\bcryptprimitives.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\uxtheme.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\clbcatq.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\ado\msado15.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\advapi32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\sechost.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msdart.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\oledb32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\bcrypt.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\dpapi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.3636_none_a863d714867441db\comctl32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\comsvcs.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\sqloledb.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\crypt32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\netapi32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\msdatl3.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\cryptbase.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\version.dll”,Cannot find or open the PDB file
“ado.exe”: 已卸载“C:\Windows\SysWOW64\version.dll”
“ado.exe”: 已加载“C:\Windows\SysWOW64\dbnetlib.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\ws2_32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\security.dll”,Cannot find or open the PDB file
“ado.exe”: 已卸载“C:\Windows\SysWOW64\security.dll”
“ado.exe”: 已加载“C:\Windows\SysWOW64\security.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\secur32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\sspicli.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msv1_0.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\NtlmShared.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\cryptdll.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\ntdsapi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\dsparse.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\mswsock.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\dnsapi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\IPHLPAPI.DLL”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\nsi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\National Instruments\Shared\mDNS Responder\nimdnsNSP.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\nimdnsResponder.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9625_none_508ef7e4bcbbe589\msvcr90.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\rasadhlp.dll”,Cannot find or open the PDB file
线程 'Win32 线程' (0x1f08) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x3174) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x10a0) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x1ac8) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x318c) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x3220) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0xe00) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x3170) 已退出,返回值为 -1073741510 (0xc000013a)。
程序“[9444] ado.exe: 本机”已退出,返回值为 -1073741510 (0xc000013a)。