高分求在自己的组件中聚合ADO组建的代码!

GoogleGeek 2002-11-16 10:34:44
高分求在自己的组件中聚合ADO组建的代码!
TNND!我自己写的代码在创建组件时竟然出现了无法写入注册标的错误!
...全文
89 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
GoogleGeek 2002-12-02
  • 打赏
  • 举报
回复
结帖
谢谢大家的关注!
paul2002 2002-11-29
  • 打赏
  • 举报
回复
那你的方法是什么?
nullhue 2002-11-28
  • 打赏
  • 举报
回复
靠,什么是聚合ADO,有什么用处?
GoogleGeek 2002-11-25
  • 打赏
  • 举报
回复
to:: paul2002()
你的方法我知道!
可能使我的clsid搞错了,我回去查一下!
flashboy 2002-11-24
  • 打赏
  • 举报
回复
ATL's forte is in the development of components but not necessarily in the use of component's. Here are some of the reasons for using ATL instead of MFC:

ATL provides dual interface support as part of its basic implementation. MFC requires a lot of additional work to add dual support.
ATL provides support for all of COM's threading models, in particular the free threading model. MFC does not and probably will never support the free threading model because MFC is thread safe only at the class level.
ATL does not require MFC's 1 meg runtime (MFC40.DLL). This isn't necessarily an issue because it is present on most systems, however it definitely increases load times for your component.
paul2002 2002-11-24
  • 打赏
  • 举报
回复
没问题嘛,我试了一下。
//in atl com
#import "C:\Program Files\Common Files\System\ADO\msado15.dll"\
no_namespace rename("EOF","EndOfFile") named_guids
/////////////////////////////////////////////////////////////////////////////
// CAdvancedMath
class ATL_NO_VTABLE CAdvancedMath :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CAdvancedMath, &CLSID_AdvancedMath>,
public IAdvancedMath
{
public:
CAdvancedMath()
{
}
~CAdvancedMath( )
{
};
DECLARE_GET_CONTROLLING_UNKNOWN()
HRESULT FinalConstruct()
{
HRESULT hr;
hr = CoCreateInstance( CLSID_Recordset,
GetControllingUnknown(),
CLSCTX_INPROC_SERVER,
IID_IUnknown,
(void**)&m_pSimpleUnknown);

return hr;
}

void FinalRelease()
{
if ( m_pSimpleUnknown )
m_pSimpleUnknown.Release();
}

DECLARE_REGISTRY_RESOURCEID(IDR_ADVANCEDMATH)

BEGIN_COM_MAP(CAdvancedMath)
COM_INTERFACE_ENTRY(IAdvancedMath)
COM_INTERFACE_ENTRY_AGGREGATE( IID_Recordset15, m_pSimpleUnknown.p )
END_COM_MAP()

public:
CComPtr<IUnknown> m_pSimpleUnknown;

// IAdvancedMath
public:
STDMETHOD(Fibonacci)( short sOp, long* plResult );
STDMETHOD(Factorial)( short sOp, long* plResult );
};
// in client
#include "..\Chapter5_Aggregate\Chapter5_Aggregate.h"
#import "C:\Program Files\Common Files\System\ADO\msado15.dll"\
no_namespace rename("EOF","EndOfFile") named_guids

int main( int argc, char *argv[] )
{
cout << "Initializing COM" << endl;

if ( FAILED( CoInitialize( NULL )))
{
cout << "Unable to initialize COM" << endl;
return -1;
}

CLSID clsid;
HRESULT hr;
cout << "Creating aggregate component" << endl;
hr = CLSIDFromProgID( L"Chapter5.Aggregate.1", &clsid );
if ( FAILED( hr ))
{
cout.setf( ios::hex, ios::basefield );
cout << "Failed to convert Progid. HR = " << hr << endl;
return -1;
}

// Use CoCreateInstance
IAdvancedMath* pMath;
hr = CoCreateInstance( clsid,
NULL,
CLSCTX_INPROC,
IID_IAdvancedMath,
(void**) &pMath );
if ( FAILED( hr ))
{
cout.setf( ios::hex, ios::basefield );
cout << "Failed to create server instance. HR = " << hr << endl;
return -1;
}


cout << "Instance created" << endl;
cout << "IAdvancedMath interface created" << endl;


// Try Recordset15, QI through IAdvancedMath
Recordset15* prec = NULL;
hr = pMath->QueryInterface( IID_Recordset15, (LPVOID*)&prec );
if ( FAILED( hr ))
{
cout << "QueryInterface() for IRecordSet15 failed" << endl;
pMath->Release();
CoUninitialize();
return -1;
}
cout<<"IRecordSet15 interface created!"<<endl;

cout << "Releasing IAdvancedMath interface" << endl;
pMath->Release();

cout << "Releasing Recordset15 interface" << endl;
prec->Release();

cout << "Shuting down COM" << endl;
CoUninitialize();

return 0;
}
BTW 0x80040154=类没有注册

GoogleGeek 2002-11-19
  • 打赏
  • 举报
回复
靠她奶奶的,难道就没人会
极度失望!
GoogleGeek 2002-11-17
  • 打赏
  • 举报
回复
我完全按照atl的聚合组建的写法,但是在客户端调用时出现了:
无法写入注册标的错误
的错误!
那位高手碰到过这样的错误!
0x80040154 ---->无法向注册表写入项
一定搞分向送!
dancing999 2002-11-17
  • 打赏
  • 举报
回复
有一本VC数据库的书,清华的<<高级VC++编程--数据库篇>>
我刚才还K呢!但是好像没有提到"聚合ADO"这个词!
或许是我看得不够仔细,呵呵!
gbstar2021 2002-11-17
  • 打赏
  • 举报
回复
CoCreateInstance 的 pUnkOuter 就可以指定聚合对象的 IUnknown 接口指针,不过被聚合的对象要支持被聚合才行。 Ado 不知道行不行,我也没试过。你的对象接口中的 QueryInterface 也要作相应的处理。推荐看看《com 技术内幕》中相关的部分。
LookSail 2002-11-17
  • 打赏
  • 举报
回复
俺比较无知,不知道"聚合ADO"是什么,所以只有帮你up
GoogleGeek 2002-11-17
  • 打赏
  • 举报
回复
靠,没人会吗?
GoogleGeek 2002-11-16
  • 打赏
  • 举报
回复
up!

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧