atlcom 和ado数据库方面的技术(来自gooyan(超级替补) 的帮助)

类别:.NET开发 点击:0 评论:0 推荐:

1.VB客户端   Dim obj As Object
    Set obj = CreateObject("AtlCom.OutFun")
    Set adoRs = obj.MyMessageBox("aaaa")

2.VC中间层
1.new/projects/ATL COM AppWizard/input AtlCom/OK/Dynamic Link Library(DLL),Suppport MFC,Support

if you want to support MTS,then check MTS/Finish

2.Mouse right Click AtlCom Classes/new Atl Object/simple Object/Names:OutFun,MTS:if you will use
Pool then you check Support IObjectControl and Can be Pooled

3.点IoutFun
把类似
[
  object,
  uuid(C06F09FA-C905-4E59-AC29-A4137948D8D7),
  dual,
  helpstring("IOutFun Interface"),
  pointer_default(unique)
 ]
 interface IOutFun : IDispatch
 {
 };
挪到importlib("stdole2.tlb")下面

4.右键点IOutFun,然后Add Method/输入MyMessageBox,parameters:[in]BSTR strInfo(如果需要返回值则为

[out,retval])
再函数中输入:MessageBox(NULL,CString(strInfo),"BOX",MB_OK);
给你一个连接SQL Server得,你把廉节字符串改一下
1.stdafx.h中加入
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
2。app文件的InitInstance中加入
if(S_OK!=OleInitialize(NULL))
{
  AfxMessageBox("初始化COM组件库错误");
}


下面就是数据库操作
_ConnectionPtr pConn;
 _RecordsetPtr  pRs;
 CString strSQL;
pConn.CreateInstance(__uuidof(Connection));
 pConn->CursorLocation=adUseClient;
 strSQL="Provider=SQLOLEDB;Server=Gooyan;DataBase=SkillsBox;UID=sa;PWD=aaaaaaaa";
 pConn->Open(_bstr_t(strSQL),"","",-1);
 
 pRs.CreateInstance(__uuidof(Recordset));
 pRs->CursorLocation=adUseClient;
 pRs->PutActiveConnection(pConn.GetInterfacePtr());
 
 pRs1.CreateInstance(__uuidof(Recordset));
 pRs1->CursorLocation=adUseClient;
 pRs1->PutActiveConnection(pConn.GetInterfacePtr());

 strSQL="select * from catalog order by cataid";
 pRs->Open(_bstr_t(strSQL),vtMissing,adOpenDynamic,adLockBatchOptimistic,adCmdText);

 

本文地址:http://com.8s8s.com/it/it42742.htm