需要重写MP3播放器
这个是我的控件处理
// WebOffice.cpp : Implementation of CWebOfficeApp and DLL registration.#include "stdafx.h"
#include "WebOffice.h"
#include "WebOfficeFrame.h"#include "comcat.h"
#include "Objsafe.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWebOfficeApp NEAR theApp;const GUID CDECL BASED_CODE _tlid =
{ 0x979c40a2, 0xa31, 0x4e95, { 0xb8, 0x3e, 0x87, 0x21, 0x41, 0x4c, 0x27, 0x94 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;////////////////////////////////////////////////////////////////////////////
// CWebOfficeApp::InitInstance - DLL initializationBOOL CWebOfficeApp::InitInstance()
{
BOOL bInit = COleControlModule::InitInstance(); if (bInit)
{
// TODO: Add your own module initialization code here.
}
m_pDocTemplate=new CMultiDocTemplate(IDI_ABOUTDLL,RUNTIME_CLASS(CWebOfficeDoc),RUNTIME_CLASS(CWebOfficeFrame),RUNTIME_CLASS(CWebOfficeView));
AddDocTemplate(m_pDocTemplate);
AfxOleInit();
return bInit;
}
////////////////////////////////////////////////////////////////////////////
// CWebOfficeApp::ExitInstance - DLL terminationint CWebOfficeApp::ExitInstance()
{
// TODO: Add your own module termination code here. return COleControlModule::ExitInstance();
}HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
{
    ICatRegister* pcr=NULL;
    HRESULT hr=S_OK;    hr=CoCreateInstance(CLSID_StdComponentCategoriesMgr,NULL,CLSCTX_INPROC_SERVER,IID_ICatRegister,(void**)&pcr);
    if(FAILED(hr))
return hr;    // Make sure the HKCR\Component Categories\{..catid...}
    // key is registered.
    CATEGORYINFO catinfo;
    catinfo.catid=catid;
    catinfo.lcid=0x0409; // english    // Make sure the provided description is not too long.
    // Only copy the first 127 characters if it is.
    int len=wcslen(catDescription);
    if(len>127)
len=127;
    wcsncpy(catinfo.szDescription,catDescription,len);
    // Make sure the description is null terminated.
    catinfo.szDescription[len]='\0';    hr=pcr->RegisterCategories(1,&catinfo);
    pcr->Release();

    return hr;
}HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{
    // Register your component categories information.
    ICatRegister* pcr=NULL;
    HRESULT hr=S_OK;
    hr=CoCreateInstance(CLSID_StdComponentCategoriesMgr,NULL,CLSCTX_INPROC_SERVER,IID_ICatRegister,(void**)&pcr);
    if(SUCCEEDED(hr))
    {
// Register this category as being "implemented" by the class.
        CATID rgcatid[1];
        rgcatid[0]=catid;
        hr=pcr->RegisterClassImplCategories(clsid,1,rgcatid);
    }
    if(pcr!=NULL)
pcr->Release();
    return hr;
}HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{
    ICatRegister* pcr=NULL;
    HRESULT hr=S_OK;    hr=CoCreateInstance(CLSID_StdComponentCategoriesMgr,NULL,CLSCTX_INPROC_SERVER,IID_ICatRegister,(void**)&pcr);
    if(SUCCEEDED(hr))
    {
// Unregister this category as being "implemented" by the class.
        CATID rgcatid[1];
        rgcatid[0]=catid;
        hr=pcr->UnRegisterClassImplCategories(clsid,1,rgcatid);
    }    if(pcr!=NULL)
pcr->Release();
    return hr;
}/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer - Adds entries to the system registrySTDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB); if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);

// 标记控件初始化安全.
    // 创建初始化安全组件种类
HRESULT hr;
    hr=CreateComponentCategory(CATID_SafeForInitializing,L"Controls safely initializable from persistent data!");
    if(FAILED(hr))
return hr;
    // 注册初始化安全
    hr=RegisterCLSIDInCategory(_tlid,CATID_SafeForInitializing);
    if(FAILED(hr))
return hr;    // 标记控件脚本安全
    // 创建脚本安全组件种类 
    hr=CreateComponentCategory(CATID_SafeForScripting,L"Controls safely scriptable!");
    if(FAILED(hr))
return hr;
    // 注册脚本安全组件种类
    hr=RegisterCLSIDInCategory(_tlid,CATID_SafeForScripting);
    if(FAILED(hr))
return hr;
return NOERROR;
}
/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer - Removes entries from the system registrySTDAPI DllUnregisterServer(void)
{
AFX_MANAGE_STATE(_afxModuleAddrThis); if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
return ResultFromScode(SELFREG_E_TYPELIB); if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
return ResultFromScode(SELFREG_E_CLASS);

// 删除控件初始化安全入口.
HRESULT hr;
    hr=UnRegisterCLSIDInCategory(_tlid,CATID_SafeForInitializing);
    if(FAILED(hr))
return hr;
    // 删除控件脚本安全入口
    hr=UnRegisterCLSIDInCategory(_tlid,CATID_SafeForScripting);
    if(FAILED(hr))
return hr;
return NOERROR;
}

解决方案 »

  1.   

    这个是问专家上的
    网页加入新做的ActiveX控件后,预览该网页,会弹出提示框编号:QA003913
    建立日期: 2001年2月22日 最后修改日期:2003年7月19日 
    所属类别: C/C++ - ActiveX技术Q Xuys: 
        用VC新建一个项目,选择MFC ActiveX Control Wizard其他为默认选项,编译之后,用Frontpage新建一个网页,加入新做的ActiveX控件后,预览该网页,会弹出提示框,但你加入微软的ActiveX控件,却不会弹出对话框;我推断可能是在编写ActiveX控件时有设置的代码,具体设置什么代码,请指教。 A回答:     (主持人注:VB的用户可以参考微软的Knowledge Base的文章:“Q182598 OWTO: Implement IObjectSafety in Visual Basic Controls”) 
        解决方法如下: 
        添加以下代码 
        //////////////////////////////////////////////////////////////// 
        // Copied from the ActiveX SDK 
        // This code is used to register and unregister a 
        // control as safe for initialization and safe for scripting 
         
        HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription) 
        { 
         
        ICatRegister* pcr = NULL ; 
        HRESULT hr = S_OK ; 
         
        hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
        NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); 
        if (FAILED(hr)) 
        return hr; 
         
        // Make sure the HKCR\Component Categories\{..catid...} 
        // key is registered 
        CATEGORYINFO catinfo; 
        catinfo.catid = catid; 
        catinfo.lcid = 0x0409 ; // english 
         
        // Make sure the provided description is not too long. 
        // Only copy the first 127 characters if it is 
        int len = wcslen(catDescription); 
        if (len>127) 
        len = 127; 
        wcsncpy(catinfo.szDescription, catDescription, len); 
        // Make sure the description is null terminated 
        catinfo.szDescription[len] = '\0'; 
         
        hr = pcr->RegisterCategories(1, &catinfo); 
        pcr->Release(); 
         
        return hr; 
        } 
         
         
        HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid) 
        { 
        // Register your component categories information. 
        ICatRegister* pcr = NULL ; 
        HRESULT hr = S_OK ; 
        hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
        NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); 
        if (SUCCEEDED(hr)) 
        { 
        // Register this category as being "implemented" by 
        // the class. 
        CATID rgcatid[1] ; 
        rgcatid[0] = catid; 
        hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid); 
        } 
         
        if (pcr != NULL) 
        pcr->Release(); 
         
        return hr; 
        } 
         
        HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid) 
        { 
        ICatRegister* pcr = NULL ; 
        HRESULT hr = S_OK ; 
        hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
        NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); 
        if (SUCCEEDED(hr)) 
        { 
        // Unregister this category as being "implemented" by 
        // the class. 
        CATID rgcatid[1] ; 
        rgcatid[0] = catid; 
        hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid); 
        } 
         
        if (pcr != NULL) 
        pcr->Release(); 
         
        return hr; 
        } 
         
         
        /***************************************** 
        在 xxxctl.cpp 文件中添加如下两个头文件 
        *****************************************/ 
        #include "comcat.h" 
        #include "objsafe.h" 
         
        /***************************************** 
        修改如下函数 
        *****************************************/ 
        BOOL CxxxCtrl::CxxxCtrlFactory::UpdateRegistry(BOOL bRegister) 
        { 
        // TODO: Verify that your control follows apartment-model threading rules. 
        // Refer to MFC TechNote 64 for more information. 
        // If your control does not conform to the apartment-model rules, then 
        // you must modify the code below, changing the 6th parameter from 
        // afxRegInsertable | afxRegApartmentThreading to afxRegInsertable. 
         
        if (bRegister) 
        { 
        HRESULT hr = S_OK ; 
         
        // register as safe for scripting 
        hr = CreateComponentCategory(CATID_SafeForScripting, 
        L"Controls that are safely scriptable"); 
         
        if (FAILED(hr)) 
        return FALSE; 
         
        hr = RegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting); 
         
        if (FAILED(hr)) 
        return FALSE; 
         
        // register as safe for initializing 
        hr = CreateComponentCategory(CATID_SafeForInitializing, 
        L"Controls safely initializable from persistent data"); 
         
        if (FAILED(hr)) 
        return FALSE; 
         
        hr = RegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing); 
         
        if (FAILED(hr)) 
        return FALSE; 
         
        return AfxOleRegisterControlClass( 
        AfxGetInstanceHandle(), 
        m_clsid, 
        m_lpszProgID, 
        IDS_DIEROLL, 
        IDB_DIEROLL, 
        afxRegInsertable | afxRegApartmentThreading, 
        _dwDierollOleMisc, 
        _tlid, 
        _wVerMajor, 
        _wVerMinor); 
        } 
        else 
        { 
        HRESULT hr = S_OK ; 
         
        hr = UnRegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting); 
         
        if (FAILED(hr)) 
        return FALSE; 
         
        hr = UnRegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing); 
         
        if (FAILED(hr)) 
        return FALSE; 
         
        return AfxOleUnregisterClass(m_clsid, m_lpszProgID); 
        } 
        } 
         
         
         
        dalinda的意见: 
        我有几点补充: 
        1.在xxxctl.h 文件中添加如下两个头文件 
        #include "comcat.h" 
        #include "objsafe.h" 
        注意:要加在类的声明前 
        2.在UpdateRegistry(BOOL bRegister)中 
        第31行的IDS_DIEROLL 
        应为IDS_XXXXXXX 
        第32行的IDB_DIEROLL 
        应为IDS_XXXXXXX 
        第34行的_dwDierollOleMisc 
        应为_dwXXXXOleMisc 
        其中的XXXX为你的工程名。