Find the solution. The source is as follows. The Forum will post it here if it cannot reply continuously. It seems to be the first article.
Http://blog.163.com/danshiming@126/blog/static/10941274820114811312523/
Http://www.d3sw.cn/Blog/article.asp? Id = 244
Http://www.cnblogs.com/phinecos/archive/2008/08/07/1263270.html
As mentioned in the above articles, paste them here to make it easier for others to view them.
The IObjectSafety interface must be added to the component. The code generated for the component interface is as follows. Add a few red lines of code to the code block.
Class atl_no_vtable catltest:
Public ccomobjectrootex <ccommultithreadmodel>,
Public ccomcoclass <catltest, & clsid_atltest>,
Public idispatchimpl <iatltest, & iid_iatltest, & libid_atlprojectlib,/* wmajor = */1,/* wminor = */0>,
Public idispatchimpl <iatladd, & iid_iatladd, & libid_atlprojectlib,/* wmajor = */1,/* wminor = */0>,
Public idispatchimpl <isub, & __ uuidof (isub), & libid_atlprojectlib,/* wmajor = */1,/* wminor = */0>,
Public iobjectsafetyimpl <enter the Interface Class Name catltest, interfacesafe_for_untrusted_caller>
{
Public:
Catltest ()
{
}
Declare_registry_resourceid (idr_atltest)
Begin_com_map (catltest)
Com_interface_entry (iatltest)
Com_interface_entry (iatladd)
Com_interface_entry (isub)
Com_interface_entry (IObjectSafety)
End_com_map ()
Note: add the header file: # include <atlctl. h>