惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - dgz

c/c++之预处理 派生类的拷贝构造函数 虚函数和接口的差别 CALLBACK 函数 vc中LNK2001错误以及解决方案(转载) C++类对象的拷贝构造函数(转载) C++的static关键字(转载) 指针常量,常量指针 static 和 const的解释(转载) 数据类型转换:static_cast,const_cast等用法(转载) static用法小结(转载) Windows多线程多任务设计初步 最简单的完成端口代码 SOCKET模型之重叠I/O篇(转贴) WindowsSockets2.0:使用完成端口高性能,可扩展性Winsock服务程序(转载) CListCtrl 使用技巧(转载) C++字符串—— Win32 字符编码 com+调试 com+返回recordset
如何在VC++ 编写的组件中使用 ADO
dgz · 2006-05-19 · via 博客园 - dgz

这篇文章是给那些习惯于用VB开发组件的人想转用VC++时看的。本文用一个简单的例子示范如何使用ADO Recordset 对象。
在VB中,当你想要返回一个ADO Recordset,你会这样写…
Function GetRecordset() As Object
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.Open "DSN=AdvWorks"
Set rs = cn.Execute("Select * From Customers")
Set GetRecordset = rs
End Function

那么让我们来看看用VC++如何实现呢?
在VB中,你会使用’Project->References菜单来使用其它COM组件,例如ADO。在VC++中,要使用#import声明。在你的.CPP或.H文件中插入这样一句。
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename ( "EOF", "adoEOF" )

然后加一个方法。右击ClassView ,选择 Add Method。
Method Name: GetRecordset
Parameters: [out, retval] IDispatch **RS]
现在是关键…
STDMETHODIMP CADOSample::GetRecordset(IDispatch **RS)
{
_ConnectionPtr pCN;
_RecordsetPtr pRS;
_variant_t vtEmpty;
pCN.CreateInstance(__uuidof(Connection));
pCN->Open("DSN=AdvWorks", "", "", -1);
pRS = pCN->Execute("Select * From Customers",
&vtEmpty, adCmdUnknown);
pRS->QueryInterface(IID_IDispatch,
(void**) RS);
return S_OK;
}

看看,VC++程序几乎与VB一模一样,谁说VC++难用?
Jan.14 2001