我建了个MFC DLL工程,然后用建立类向导->Add Class->From a type library,选中这个控件的OCX文件,从中选用到的类,然后加入代码、编译、执行,中间没任何问题,但是得到的结果就是不对,我试了一下,EXE中这么使用也不行,此路不通。
    换个方法,建MFC DLL工程之后,加入1个对话框,在里面加入该ActiveX控件,再用建立类向导,然后加入代码、编译、执行,中间没任何问题,如果是EXE就正确,如果是DLL,其他程序调用该DLL,执行到该ActiveX控件就出错:
Debug Assertion Failed!
Program: ...........
File: winocc.cpp
Line: 345
    看了一下winocc.cpp, 里面345行是  :
ASSERT(m_pCtrlSite != NULL);    // not an OLE control (not yet, at least)我在大富翁论坛也提了同样的问题,还没解决:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3036365
大富翁中我另外一个帖子,是为了同一件事,但解决方法不同,如果那个帖子有办法就更好了:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3038998

解决方案 »

  1.   

    AfxEnableControlContainer();
    你在初始化的地方调用这个就可以了。
      

  2.   

    我加了AfxEnableControlContainer();
    出同样的错。我另外一个帖子,是为了同一件事,但解决方法不同,如果那个帖子有办法就更好了:
    http://community.csdn.net/Expert/topic/3949/3949114.xml?temp=.3456079
      

  3.   

    AfxEnableControlContainer 
    Call this function in your application object's InitInstance function to enable support for containment of OLE controls.void AfxEnableControlContainer( );
      

  4.   

    我试过,
       AfxEnableControlContainer( );
    不管是加在InitInstance中还是加在调用控件之前都没用,还是出错
      

  5.   

    前面问题还是没有解决,后来根据别人的提示,我换个方法还是有问题,我是这么做的:
    注册OCX,
    然后新建MFC DLL工程,
    选工程->添加工程->Components and Controls,
    选中OCX文件,
    按Insert按钮,就出错了:
       The ActiveX Control is not registered properly, or its type library version number is incorrect.
        Try registering the control by removing and importing it in the component Gallery
    我的方法有问题吗?还是有其他原因?  
      

  6.   

    是MFC extend dll还是mfc regular dll,如果是后者,但create dialog之前要进行模块状态切换。AFX_MANAGE_STATE(AfxGetStaticModule());
      

  7.   

    To Cline:
        不是你说的原因。
    是mfc regular dll,有
    AFX_MANAGE_STATE(AfxGetStaticModuleState());