第一次打算使用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.
博主首次用ADO进行数据库编程,程序为对话框,操作主要在工作线程。起初在OnInitDialog中用CoInitialize(NULL),工作线程里_ConnectionPtr对象的createinstance操作失败,提示找不到ADODB.Connection对象。将CoInitialize(NULL)放工作线程后正常,前辈解释需在当前线程初始化COM库。
4164

被折叠的 条评论
为什么被折叠?



