还是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.batD:\develop\InsideCom\Cmpent1\Debug>regsvr32 -s Cmpnt1.dllD:\develop\InsideCom\Cmpent1\Debug>regsvr32 -s Cmpnt2.dllD:\develop\InsideCom\Cmpent1\Debug>但我再试了一下,运行client.exe,也是调试着进的,还是在::CoCreateInstance这里失败了。  
我上面的过程到底错在了哪里呢?   麻烦会的朋友帮忙一下。  谢谢!

解决方案 »

  1.   

    还有是VC6不像VC2008。里面的workspace不会有一个总的输出文件夹,一般情况下是怎样组织多个工程的?
      

  2.   

    CoCreateInstance 返回的是什么错误?
    vs2008中可以见solution,然后加入过个工程...
      

  3.   

    补充一下
    1.可以设置存放编译中间文件的路径和最终链接输出文件的文件夹
    2.可以在Post-Build中设置自动注册
    3. vc6.0也可以设置项目工程的依赖关系,只要exe项目依赖前两个dll项目,则在编译exe项目之前会自动变量所依赖的所有项目4. CoCreateInstance调用失败,如ls说说,查看错误信息。
      

  4.   

    -2147221164错误表示CLSID_Component1组件没有注册
      

  5.   

    cout << "Could not create component: " << hex << hr << endl ;Could not create component:80040154
      

  6.   

    估计是下面的注册失败了。
    regsvr32 -s Cmpnt1.dll
    regsvr32 -s Cmpnt2.dll
      

  7.   

    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   
      &copy;   2000   Microsoft   Corporation.   All   rights   reserved.   Terms   of   Use.  
      

  8.   


    按照你这么说我的电脑是少了ATL.DLL?那我要看一下。 谢谢
      

  9.   

    HRESULT的值都是有固定的含义的,你可以打开winerror.h文件,查找 80040154,能得到下面的信息:
    //
    // MessageId: REGDB_E_CLASSNOTREG
    //
    // MessageText:
    //
    // Class not registered
    //
    #define REGDB_E_CLASSNOTREG              _HRESULT_TYPEDEF_(0x80040154L)
      

  10.   

    使用error lookup工具也可以查看在tools->error lookup
      

  11.   

    我电脑上有atl.DLL,在system32下。我试过了这样: regsvr32 -s atl.dll再重新到debug下运行了一次register.bat重新运行了一次程序,但还是出现同样的错误。 为什么呢?
      

  12.   

    @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删除,看看提示是否注册成功
      

  13.   

    编译顺序的问题。可能在重新编译过程中,有些dll,会先被删除。正确的顺序是,先build组件,然后注册,最后编译exe。
      

  14.   

    去注册表里 搜索你的CLSID看看正确与否
      

  15.   


    我的顺序是正确的,那两个DLL也还在啊。
      

  16.   


    这个我也想过,但找那些CLSID还是很麻烦的啊。
      

  17.   

    不写bat文件,直接用cmd来注册,看看有啥错误提示没注册表支持搜索的。