gis-liang 发表于 2007-6-13 15:14:00

[求助]应用ADO 无法初始化 指针

<p>#include "StdAfx.h"<br/>#include "StdArx.h"</p><p>//-----------------------------------------------------------------------------<br/>// This is command 'LINK, by&nbsp; , , <br/>void asdklink()<br/>{<br/>#ifdef OARXWIZDEBUG<br/>&nbsp;acutPrintf ("\nOARXWIZDEBUG - asdklink() called.");<br/>#endif // OARXWIZDEBUG</p><p>&nbsp;// TODO: Implement the command<br/>&nbsp;::CoInitialize(NULL);<br/>&nbsp;ADO::_ConnectionPtr connPtr;<br/>&nbsp;<br/>&nbsp;//AfxGetModuleState()-&gt;m_dwVersion&nbsp;&nbsp; =&nbsp;&nbsp; 0x0601;&nbsp;&nbsp; <br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; //&nbsp; HRESULT hr =connPtr.CreateInstance("ADODB.Connection");<br/>&nbsp;&nbsp;&nbsp; HRESULT hr =connPtr.CreateInstance(__uuidof(Connection));<br/>&nbsp;if(SUCCEEDED(hr))<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf("Create Instance SUCCEEDED!");<br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("Create Instance FAILED!");<br/>&nbsp;}<br/>&nbsp;CString strConn;<br/>&nbsp;strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\PipeData.mdb";</p><p>&nbsp;_bstr_t varConn(strConn);<br/>&nbsp;if (FAILED(connPtr-&gt;Open(varConn,"","",-1)))<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf("Can not open Database!");<br/>&nbsp;&nbsp;connPtr.Release();<br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;ADO::_RecordsetPtr recdPtr;<br/>&nbsp;if (FAILED(recdPtr.CreateInstance("ADODB.Recordset")))<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf("recdPtr Create Instance failed!");<br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;CString strSql;<br/>&nbsp;strSql="select *from (. AS a INNER JOIN . AS b ON a.起始点号=b.起点) INNER JOIN . AS c ON a.终止点号=c.终点";<br/>&nbsp;_variant_t varSql(strSql);<br/>&nbsp;//_variant_t varCon(strConn);<br/>&nbsp;if(FAILED(recdPtr-&gt;Open(varSql,connPtr.GetInterfacePtr(),ADO::adOpenDynamic,ADO::adLockOptimistic,ADO::adCmdText)))<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf("Open table failed!");<br/>&nbsp;&nbsp;recdPtr.Release();<br/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf("成功");<br/>&nbsp;}<br/>&nbsp;<br/>&nbsp;<br/>}</p><p>StdAfx.h已经引用了#import "C:\Program Files\Common Files\System\ado\msado15.dll" rename_namespace("ADO") rename("EOF","adoEOF") </p><p>BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)<br/>{&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp; AfxOleInit();</p><p>}</p>

gis-liang 发表于 2007-6-13 15:16:00

[求助]应用ADO 无法初始化 指针

<p>不能初始化 _ConnectionPtr</p><p>请各位大师指教.</p>

gis-liang 发表于 2007-6-14 09:09:00

<p>困扰我很久了,希望那位高手给以指点。</p>
页: [1]
查看完整版本: [求助]应用ADO 无法初始化 指针