还是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这里失败了。
我上面的过程到底错在了哪里呢? 麻烦会的朋友帮忙一下。 谢谢!
我编译出了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这里失败了。
我上面的过程到底错在了哪里呢? 麻烦会的朋友帮忙一下。 谢谢!
vs2008中可以见solution,然后加入过个工程...
1.可以设置存放编译中间文件的路径和最终链接输出文件的文件夹
2.可以在Post-Build中设置自动注册
3. vc6.0也可以设置项目工程的依赖关系,只要exe项目依赖前两个dll项目,则在编译exe项目之前会自动变量所依赖的所有项目4. CoCreateInstance调用失败,如ls说说,查看错误信息。
regsvr32 -s Cmpnt1.dll
regsvr32 -s Cmpnt2.dll
--------------------------------------------------------------------------------
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.
按照你这么说我的电脑是少了ATL.DLL?那我要看一下。 谢谢
//
// MessageId: REGDB_E_CLASSNOTREG
//
// MessageText:
//
// Class not registered
//
#define REGDB_E_CLASSNOTREG _HRESULT_TYPEDEF_(0x80040154L)
rem
rem Register.bat
rem Registration file for Chapter 8 Example 2
rem
echo on
regsvr32 -s Cmpnt1.dll
regsvr32 -s Cmpnt2.dll 你将-s删除,看看提示是否注册成功
我的顺序是正确的,那两个DLL也还在啊。
这个我也想过,但找那些CLSID还是很麻烦的啊。