COM 7.0以后有这样一个宏DECLARE_REGISTRY_APPID_RESOURCEID
在VS03以后的版本中,ATL工程中会自动添加这样的代码
class CXXModule : public CAtlDllModuleT< CXXModule >
{
public :
DECLARE_LIBID(LIBID_xinstallerLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_XX, "{classid}")
};
CXXModule _AtlModule;
_CAtlDllModuleT继承自CAtlModule
看MSDN解释说AppId在DCOM中使用,主要是为了集中注册表中分散的属性值,觉得这个解释相当含糊。
那么什么时候才需要指定这个AppId呢?看到一个老外回答这个问题,不翻译了,原文看着比较好。
You need to specify an appid if one of the following is true:
- Your COM object is hosted in a service
- Your COM object has custom launch permissions
- Your COM object has custom access permissions
- You want to specify a default bitness for the COM server when launching an out-of-proc COM object.
- Your COM object runs as another user
- Your COM object needs to run on another system (unless you specify a COSERVERINFO in your call to CoCreateInstanceEx)
- Your COM object needs to set the default authentication level (used if you don't call CoInitializeSecurity directly)
- Your COM object needs to specify the RPC endpoints for communication (or the TCP port number, etc)
- Your COM object should run on the same machine as the storage (ActivateAtStorage)
- Your COM object runs using the DLL surrogate
- Your COM object needs to set its software restriction trust level
If those are true, you need an appid, otherwise it's unnecessary (and takes up space on the disk).