我用MFC ActiveX ControlWizard向导制作的ActiveX控件。在VB中正常使用。当要插入到VC中的时候提示:
Unable to open this ActiveX Control。Make sure the control contains a valid type library。请问是什么原因引起的。应该如何解决。(急)

解决方案 »

  1.   

    a valid type library。
    ==============
    需要tlb文件。一种包含相关类型信息的文件,VC通过其产生和控件相关的类!
      

  2.   

    你的ActiveX有没有这段代码啊:
    STDAPI DllRegisterServer(void)
    {
    AFX_MANAGE_STATE(_afxModuleAddrThis); if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
    return ResultFromScode(SELFREG_E_TYPELIB); if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
    return ResultFromScode(SELFREG_E_CLASS); return NOERROR;
    }
      

  3.   

    to alaisalaix(流水落花春去也,天上人间)
    有这段代码to vcleaner(我没当大哥很久了.......) 
    插入OCX控件还要用到tlb文件吗? 如果我把ocx控件发行给客户怎么办?也要带着tlb发行吗?我也试过新作一个OCX是没有问题。可是我这个工程已经很庞大了,不能随便重新做一个了。就是要想办法在这个工程上来修复才行。
      

  4.   

    有可能是ActiveX空间版本的问题。怎么解决还不太清楚...
      

  5.   

    在VC中我用别人的OCX的时候,一般都#import一下,:)
      

  6.   

    注册,
    然后project->add to project->->components... activex 然后选择即可
    如果不行,打开classwizard 里面有new,直接选择ocx也可以 但一般如果ocx里面有二级对象时用这个方法
      

  7.   

    问题还没有解决,sinall说的 IDL 是这个吗?
    #include <olectl.h>
    #include <idispids.h>[ uuid(99C9B263-7404-11D3-9FC0-00A0C932550C), version(1.0),
      helpfile("Mycom.hlp"),
      helpstring("Mycom ActiveX Control module"),
      control ]
    library MYCOMLib
    {
    importlib(STDOLE_TLB);
    importlib(STDTYPE_TLB); //  Primary dispatch interface for CMyView [ uuid(99C9B264-7404-11D3-9FC0-00A0C932550C),
      helpstring("Dispatch interface for Drawcom Control"), hidden ]
    dispinterface _DMycom
    {
    properties:
    // NOTE - ClassWizard will maintain property information here.
    //    Use extreme caution when editing this section.
    //{{AFX_ODL_PROP(CMyView)
    [id(1)] BSTR ServerAddress;
    [id(2)] BSTR ViewName;
    [id(4)] BOOL FullScreen;
    [id(5)] short UserLevel;
    [id(6)] long WebPort;
    //}}AFX_ODL_PROP methods:
    // NOTE - ClassWizard will maintain method information here.
    //    Use extreme caution when editing this section.
    //{{AFX_ODL_METHOD(CMyView)
    [id(3)] void DisPlay(BSTR WinName); //whf添加
    //}}AFX_ODL_METHOD
    }; //  Event dispatch interface for CMyView [ uuid(99C9B265-7404-11D3-9FC0-00A0C932550C),
      helpstring("Event interface for Mycom Control") ]
    dispinterface _DMycomEvents
    {
    properties:
    //  Event interface has no properties methods:
    // NOTE - ClassWizard will maintain event information here.
    //    Use extreme caution when editing this section.
    //{{AFX_ODL_EVENT(CMyView)
    [id(DISPID_READYSTATECHANGE)] void ReadyStateChange();
    [id(1)] void StateChange(short nState);
    //}}AFX_ODL_EVENT
    }; //  Class information for CMyView [ uuid(99C9B266-7404-11D3-9FC0-00A0C932550C),
      helpstring("Mycom Control"), control ]
    coclass Mycom
    {
    [default] dispinterface _DMycom;
    [default, source] dispinterface _DMycomEvents;
    };
    //{{AFX_APPEND_ODL}}
    //}}AFX_APPEND_ODL}}
    };
      

  8.   

    试一下添加新类时,添加类型库中的MFC类,直接从OCX文件中提取
      

  9.   

    用添加类添加的是_DMycom 和 _DMycomEvents这样的类.我感觉应该是CMyCom之类的类才对啊.
      

  10.   

    注册,
    然后project->add to project->->components... activex 然后选择即可
    直接当作普通的控件用,
    就是把组件廊中标有ocx的那个控件拖到你需要的地方,然后在再给ocx提供数据
      

  11.   

    问题是我在project->add to project->->components... activex 的对话框中刚刚选中这个控件都还没有点击确定的时候就弹出了"Unable to open this ActiveX Control。Make sure the control contains a valid type library"这个对话框.不知道是为什么.
      

  12.   

    看不出来有什么不妥的地方。
    既然VB可以使用,那么type library应该没什么问题。楼主可以重试一下(不需要添加那么多变量和方法)。看能否使用。