📄 subject_42331.htm
字号:
<blockquote><p>
回复者:笑笑生 回复日期:2003-06-03 10:00:15
<br>内容:智能指针一般自己定义的时候,使用CComPtr模板类(好像叫模板类吧)定义的。在用#import是,C++会自动生成智能指针,不用自己定义。所以,虽然自己没有显示定义智能指针,但用#import导入COM(ADO也是个COM)时,会自动定义智能指针。在msado15.tlh里有这样一段:<BR>//<BR>// Smart pointer typedef declarations<BR>//<BR><BR>_COM_SMARTPTR_TYPEDEF(_Collection, __uuidof(_Collection));<BR>。。。。。。<BR>_COM_SMARTPTR_TYPEDEF(_Recordset, __uuidof(_Recordset));<BR>。。。。。。。<BR><BR>就是智能指针的定义,在这里使用_COM_SMARTPTR_TYPEDEF()宏(好像叫宏吧)定义的。可以在msdn里看看CComPtr和_COM_SMARTPTR_TYPEDEF的帮助文件。<BR><BR>_bstr_t时BSTR类型的C++封装类,BSTR类型也是COM的数据类型,可以把它看成一个字符串类,里面可以保存UNICODE码的字符串,在msdn里可以找到_bstr_t的相关资料,也可以查找BSTR类型的帮助文件看看,或者CComBSTR类型的帮助文件。<BR>_variant_t时VARIANT类型的C++封装类,VARIANT类型也是COM的数据类型,是一个比较复杂的数据类型,里面可以保存字符窜,长整,短整,数组等很多数据类型,它的成员变量.vt就是用来指示_variant_t类型变量里面保存的数据的数据类型的,vt也可能代表Variant Type的意思。VT_NULL是一个表示一个VARIANT类型的NULL值的常量。<BR><BR>以前没用过Recordset的GetCollect方法,一般取Recordset里面制的时候,都是这样(我是这样做的,不知道常规方法是怎样的):<BR>_variant_t TheValue;<BR>FieldPtr pfldName;<BR>while(!(m_pRecordset->adoEOF()))<BR>{<BR> pfldName=m_pRecordset->Fields->GetItem("au_lname");<BR> TheValue=pfldName->Value;<BR> if(TheValue.vt!=VT_NULL)<BR> {<BR> m_list1.AddString((char*)_bstr_t(TheValue));<BR> //将该值加入到列表控件中<BR> }<BR> m_pRecordset->MoveNext();<BR>}<BR><BR>http://www.devguru.com/Technologies/ado/quickref/ado_intro.html<BR><BR>这是个挺好的关于ADO的网站,里面有挺详细帮助,还有例子,不过例子多是用VBScript写的,看不太懂。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:阿志 回复日期:2003-06-03 10:30:37
<br>内容:我只是搜索了tli\tlh文件没有字符串“_ConnectionPtr”,就盲目判断,没有注意到宏<BR>谢谢楼上
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:阿志 回复日期:2003-06-03 23:31:34
<br>内容:果然如笑笑生大哥所说,我搜索msdn,关键字是_COM_SMARTPTR_TYPEDEF<BR><BR>艘到了一片有用的文章<BR> ms-help://MS.VSCC/MS.MSDNVS.2052/dnado/html/msdn_adorosest.htm<BR>[标题部分:]<BR>ADO Technical Articles <BR>Implementing ADO with Various Development Languages<BR>The ADO Rosetta Stone<BR><BR><BR>。。。。<BR><BR>Creating an ADO Project with #import<BR>The following ADO code snippet demonstrates how to get started with #import.<BR><BR>Listing 7: Opening an ADO Recordset in Visual C++ with #import<BR><BR>#include <windows.h><BR>#import <msado15.dll> rename("EOF", "adoEOF")<BR>... Init Ole ... <BR>void main()<BR>{<BR> HRESULT hr = S_OK;<BR> ADODB::_RecordsetPtr Rs1 = NULL;<BR> _bstr_t Connect( "DSN=AdoDemo;UID=admin;PWD=;" );<BR> _bstr_t Source ( "SELECT * FROM Authors" );<BR><BR> hr = Rs1.CreateInstance( __uuidof( ADODB::Recordset ) );<BR> Rs1->Open( Source, Connect, <BR> ADODB::adOpenForwardOnly, <BR> ADODB::adLockReadOnly, -1 );<BR> Rs1->Close();<BR> Rs1 = NULL;<BR> ::MessageBox( NULL, "Success!", "", MB_OK );<BR><BR>。。。<BR>The code declares an instance of the ADO Recordset smart pointer named Rs1, but doesn't instantiate the actual ADO Recordset object until later with the CreateInstance method. Note that #import generates the smart pointer definitions in the .tlh file with the _COM_SMARTPTR_TYPEDEF macro, as follows:<BR><BR>_COM_SMARTPTR_TYPEDEF(_Recordset, __uuidof(_Recordset));<BR><BR>To determine the name of any smart pointer that #import generates for use in your code, examine the list of _COM_SMARTPTR_TYPEDEF macros generated in the .tlh file and add a "Ptr" to have the name of the smart pointer class created by the macro. Thus, _Recordset in this definition equates to the smart pointer derived class _RecordsetPtr. The use of an underscore preceding an ADO object is not required; it depends on how the object was defined in the ADO type library.<BR><BR>笑笑生大哥说的没错
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:titany 回复日期:2003-06-03 23:40:21
<br>内容:m_msfgrid.SetDataSource((LPDISPATCH*)m_pRecordset->DataSource);<BR>m_msfgrid.SetDataSource((LPDISPATCH*)m_pRecordset->GetDataSource());<BR><BR>我想把为msfgrid控件设置datasource,怎么上面两种办法都不行阿?<BR>应该怎样设置的?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:笑笑生 回复日期:2003-06-04 09:36:53
<br>内容:如果想显示记录集的话,用Microsoft DataGrid Control很方便,用它的m_ctrlDataGrid.SetRefDataSource(m_pRecordset)方法设一下就行了。<BR>m_msfgrid没用过:)。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:titany 回复日期:2003-06-04 15:07:34
<br>内容:datagrid能显示图片吗?好像msfgrid可以,datagrid我会射,不过msfgrid我射不成,难道要一个一个格的填,太麻烦了把
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:二极管 回复日期:2003-08-13 22:57:41
<br>内容:我要仔细看看
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -