我用MFC ActiveX ControlWizard向导制作的ActiveX控件。在VB中正常使用。当要插入到VC中的时候提示:
Unable to open this ActiveX Control。Make sure the control contains a valid type library。请问是什么原因引起的。应该如何解决。(急)
Unable to open this ActiveX Control。Make sure the control contains a valid type library。请问是什么原因引起的。应该如何解决。(急)
==============
需要tlb文件。一种包含相关类型信息的文件,VC通过其产生和控件相关的类!
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;
}
有这段代码to vcleaner(我没当大哥很久了.......)
插入OCX控件还要用到tlb文件吗? 如果我把ocx控件发行给客户怎么办?也要带着tlb发行吗?我也试过新作一个OCX是没有问题。可是我这个工程已经很庞大了,不能随便重新做一个了。就是要想办法在这个工程上来修复才行。
然后project->add to project->->components... activex 然后选择即可
如果不行,打开classwizard 里面有new,直接选择ocx也可以 但一般如果ocx里面有二级对象时用这个方法
#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}}
};
然后project->add to project->->components... activex 然后选择即可
直接当作普通的控件用,
就是把组件廊中标有ocx的那个控件拖到你需要的地方,然后在再给ocx提供数据
既然VB可以使用,那么type library应该没什么问题。楼主可以重试一下(不需要添加那么多变量和方法)。看能否使用。