晕,还是有问题,再问关于Inside COM的

HelloDan 2010-01-05 10:16:40
还是Inside COM第8章聚合的例子。我按照各们好友教我的方法,最后是能导出两个组件,cmpnt1.dll和cmpnt2.dll了。我是建一个cmpnt1的workspace,里面加入所有的工程,分别有,cmpnt1,cmpnt2和测试用的例子client三个工程,编译的输出都在debug文件夹下。

我编译出了cmpnt1.dll后编译cmpnt2有问题,是关于那个*.sbr文件的,我把debug下除cmpnt1.dll的所有东西都删除了,再编译,可以得到cmpnt2.dll. 然后的client工程编译时也要删除上面所说的文件,只留下cmpnt1.dll和cmpnt2.dll。最后得到了client.exe。 我想调试跟踪程序的过程的,但发现
HRESULT hr = ::CoCreateInstance(CLSID_Component1,
NULL,
CLSCTX_INPROC_SERVER,
IID_IX,
(void**)&pIX) ;
这里面失败了。 我想可能是我没有注册DLL吧。就用了书上带的那个Register.bat注册。

@echo off
rem
rem Register.bat
rem Registration file for Chapter 8 Example 2
rem
echo on
regsvr32 -s Cmpnt1.dll
regsvr32 -s Cmpnt2.dll

在命令行里面在debug文件夹下运行了。

D:\develop\InsideCom\Cmpent1\Debug>Register.bat

D:\develop\InsideCom\Cmpent1\Debug>regsvr32 -s Cmpnt1.dll

D:\develop\InsideCom\Cmpent1\Debug>regsvr32 -s Cmpnt2.dll

D:\develop\InsideCom\Cmpent1\Debug>

但我再试了一下,运行client.exe,也是调试着进的,还是在::CoCreateInstance这里失败了。


我上面的过程到底错在了哪里呢? 麻烦会的朋友帮忙一下。 谢谢!
...全文
105 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
HelloDan 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 tttyd 的回复:]
@echo off
rem
rem Register.bat
rem Registration file for Chapter 8 Example 2
rem
echo on
regsvr32-s Cmpnt1.dll
regsvr32-s Cmpnt2.dll

你将-s删除,看看提示是否注册成功
[/Quote]

非常感谢,真的成功了。。。
WaistCoat11 2010-01-06
  • 打赏
  • 举报
回复
不写bat文件,直接用cmd来注册,看看有啥错误提示没

注册表支持搜索的。
leer168 2010-01-06
  • 打赏
  • 举报
回复
去注册表里 搜索你的CLSID看看正确与否
HelloDan 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 leer168 的回复:]
去注册表里 搜索你的CLSID看看正确与否
[/Quote]

这个我也想过,但找那些CLSID还是很麻烦的啊。
HelloDan 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 vieri_ch 的回复:]
编译顺序的问题。可能在重新编译过程中,有些dll,会先被删除。

正确的顺序是,先build组件,然后注册,最后编译exe。
[/Quote]

我的顺序是正确的,那两个DLL也还在啊。
HelloDan 2010-01-06
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 tttyd 的回复:]
@echo off
rem
rem Register.bat
rem Registration file for Chapter 8 Example 2
rem
echo on
regsvr32-s Cmpnt1.dll
regsvr32-s Cmpnt2.dll

你将-s删除,看看提示是否注册成功
[/Quote]

谢谢,我晚上回去试一下。
尘雨 2010-01-06
  • 打赏
  • 举报
回复
编译顺序的问题。可能在重新编译过程中,有些dll,会先被删除。

正确的顺序是,先build组件,然后注册,最后编译exe。
雪影 2010-01-05
  • 打赏
  • 举报
回复
@echo off
rem
rem Register.bat
rem Registration file for Chapter 8 Example 2
rem
echo on
regsvr32 -s Cmpnt1.dll
regsvr32 -s Cmpnt2.dll

你将-s删除,看看提示是否注册成功
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 tttyd 的回复:]
使用error lookup工具也可以查看

在tools->error lookup
[/Quote]
很实用,谢谢
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
我电脑上有atl.DLL,在system32下。我试过了这样: regsvr32 -s atl.dll

再重新到debug下运行了一次register.bat

重新运行了一次程序,但还是出现同样的错误。 为什么呢?
雪影 2010-01-05
  • 打赏
  • 举报
回复
使用error lookup工具也可以查看

在tools->error lookup
jameshooo 2010-01-05
  • 打赏
  • 举报
回复
HRESULT的值都是有固定的含义的,你可以打开winerror.h文件,查找 80040154,能得到下面的信息:
//
// MessageId: REGDB_E_CLASSNOTREG
//
// MessageText:
//
// Class not registered
//
#define REGDB_E_CLASSNOTREG _HRESULT_TYPEDEF_(0x80040154L)
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 oyljerry 的回复:]
PRB:  Registering  ATL  Server  Causes  0x80040154  Error

  --------------------------------------------------------------------------------
  The  information  in  this  article  applies  to:

  The  Microsoft  Active  Template  Library  (ATL),  versions  2.0,  2.1,  3.0,  included  with:
  Microsoft  Visual  C++,  32-bit  Editions,  versions  5.0,  6.0

  --------------------------------------------------------------------------------


  SYMPTOMS
  When  you  register  an  ATL  server,  you  might  get  error  0x80040154  (Class  not  registered).  For  DLLs,  REGSVR32.exe  returns  this  error.  For  .exes,  the  call  to  _Module::RegisterServer(CComModule::RegisterServer)  in  _tWinMain()  returns  this  error.



  CAUSE
  ATL.dll  is  not  installed,  or  it  is  not  registered.



  RESOLUTION
  Install  ATL.dll  in  the  Windows\System  or  Winnt\System32  directory  and  register  it  using  REGSVR32.exe.  There  are  UNICODE  and  ANSI  versions  of  ATL.dll.  Install  the  appropriate  version  on  the  target  operating  system  (that  is,  UNICODE  for  Windows  NT  and  ANSI  for  Windows  95  or  Windows  98).

  As  an  alternative,  do  not  use  ATL.dll.  When  you  rebuild  your  ATL  server  with  a  build  target  of  ReleaseMinDependency,  the  code  in  ATL.dll  is  statically  linked  to  your  project.

  Even  for  a  'Release  MinDependency'  ATL.dll  may  need  to  be  shipped.

  For  additional  information,  click  the  article  number  below  to  view  the  article  in  the  Microsoft  Knowledge  Base:

  Q244955  PRB:  MinDependency  Project  May  Need  to  Include  Atl.dll



  STATUS
  This  behavior  is  by  design.



  MORE  INFORMATION
  ATL  has  a  registrar  component  that  is  used  during  registration.  This  component  resides  in  ATL.dll.  During  registration,  the  error  0x80040154  is  returned  from  CoCreateInstance()  when  it  fails  to  create  the  registrar  component.

  Location  of  ATL.DLL  in  the  VC  5.0  CD:
  OS\SYSTEM  (UNICODE  version)
  OS\SYSTEM\ANSI  (ANSI  version)
  Location  of  ATL.DLL  in  the  VC  6.0  CD:
  DevStudio\VC\Redist  (UNICODE  version)
  DevStudio\VC\Redist\Ansi  (ANSI  version)



  REFERENCES
  MSDN  Library:  Registrar,  ATL  Registry  Component;  Regsvr32,  using

  (c)  Microsoft  Corporation  1999,  All  Rights  Reserved.  Contributions  by  Samson  Tanrena,  Microsoft  Corporation.



  Additional  query  words:  REGDB_E_CLASSNOTREG

  Keywords  :  kbActiveX  kbATL200  kbATL210  kbCOMt  kbCtrlCreate  kbInprocSvr  kbRegistry  kbVC500  kbVC600  kbATL300  kbfaq
  Version  :  WINDOWS:2.0,2.1,3.0
  Platform  :  WINDOWS
  Issue  type  :  kbprb
  Technology  :  kbvcSearch


  Last  Reviewed:  April  3,  2000
  ©  2000  Microsoft  Corporation.  All  rights  reserved.  Terms  of  Use.
[/Quote]

按照你这么说我的电脑是少了ATL.DLL?那我要看一下。 谢谢
oyljerry 2010-01-05
  • 打赏
  • 举报
回复
PRB: Registering ATL Server Causes 0x80040154 Error

--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Active Template Library (ATL), versions 2.0, 2.1, 3.0, included with:
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0

--------------------------------------------------------------------------------


SYMPTOMS
When you register an ATL server, you might get error 0x80040154 (Class not registered). For DLLs, REGSVR32.exe returns this error. For .exes, the call to _Module::RegisterServer(CComModule::RegisterServer) in _tWinMain() returns this error.



CAUSE
ATL.dll is not installed, or it is not registered.



RESOLUTION
Install ATL.dll in the Windows\System or Winnt\System32 directory and register it using REGSVR32.exe. There are UNICODE and ANSI versions of ATL.dll. Install the appropriate version on the target operating system (that is, UNICODE for Windows NT and ANSI for Windows 95 or Windows 98).

As an alternative, do not use ATL.dll. When you rebuild your ATL server with a build target of ReleaseMinDependency, the code in ATL.dll is statically linked to your project.

Even for a 'Release MinDependency' ATL.dll may need to be shipped.

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

Q244955 PRB: MinDependency Project May Need to Include Atl.dll



STATUS
This behavior is by design.



MORE INFORMATION
ATL has a registrar component that is used during registration. This component resides in ATL.dll. During registration, the error 0x80040154 is returned from CoCreateInstance() when it fails to create the registrar component.

Location of ATL.DLL in the VC 5.0 CD:
OS\SYSTEM (UNICODE version)
OS\SYSTEM\ANSI (ANSI version)
Location of ATL.DLL in the VC 6.0 CD:
DevStudio\VC\Redist (UNICODE version)
DevStudio\VC\Redist\Ansi (ANSI version)



REFERENCES
MSDN Library: Registrar, ATL Registry Component; Regsvr32, using

(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Samson Tanrena, Microsoft Corporation.



Additional query words: REGDB_E_CLASSNOTREG

Keywords : kbActiveX kbATL200 kbATL210 kbCOMt kbCtrlCreate kbInprocSvr kbRegistry kbVC500 kbVC600 kbATL300 kbfaq
Version : WINDOWS:2.0,2.1,3.0
Platform : WINDOWS
Issue type : kbprb
Technology : kbvcSearch


Last Reviewed: April 3, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
雪影 2010-01-05
  • 打赏
  • 举报
回复
估计是下面的注册失败了。
regsvr32 -s Cmpnt1.dll
regsvr32 -s Cmpnt2.dll
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 tttyd 的回复:]
-2147221164错误表示CLSID_Component1组件没有注册
[/Quote]

谢谢,我想知道你一般是怎样查的,怎样知道这个值是没有注册的?
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
cout << "Could not create component: " << hex << hr << endl ;

Could not create component:80040154
雪影 2010-01-05
  • 打赏
  • 举报
回复
-2147221164错误表示CLSID_Component1组件没有注册
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
16进制是80040154
HelloDan 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tttyd 的回复:]
补充一下
1.可以设置存放编译中间文件的路径和最终链接输出文件的文件夹
2.可以在Post-Build中设置自动注册
3. vc6.0也可以设置项目工程的依赖关系,只要exe项目依赖前两个dll项目,则在编译exe项目之前会自动变量所依赖的所有项目

4. CoCreateInstance调用失败,如ls说说,查看错误信息。
[/Quote]
第一个讲得好, 我记起了好像是有, 谢谢

hr 的返回值是 -2147221164。但这些都是32位的返回值,怎样知道具体是什么原因的?
加载更多回复(4)

3,245

社区成员

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

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