ado的CoInitialize初始函数的使用?

来源:互联网 发布:html网页中嵌入php 编辑:程序博客网 时间:2024/04/29 16:48

       第一次打算使用ado进行数据库编程,我的程序是个对话框,当中的操作主要在一个工作线程中。开始的时候直接在OnInitDialog中使用CoInitialize(NULL)。问题就出来了,我在工作线程中的_ConnectionPtr对象的createinstance操作总是失败!

      我是这样使用的:connection.CreateInstance("ADODB.Connection");他给我的错误提示竟然说:找不到ADODB.Connection这个对象,我郁闷了?这是咋个搞的?

     后来,我直接把CoInitialize(NULL)直接放到我的工作线程中,一切ok!!

后来,我在网上问了些前辈,他们给我的答案是:Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA). Applications must initialize the COM library before they can call COM library functions other than CoGetMalloc and memory allocation functions.