VC7(VS2003.net)中开发ActiveX控件相关【转】
今天在VC7上开发ActiveX控件,添加函数害的我挣了一下午,现在想想真是怀恋VC6的ClassWizard啊。在网上找了很多资料,也没发现与此相关的,所以就记录下来,仅供参考啊
创建ActiveX工程后,只能靠手动添加函数,这里要注意四个地方都要修改,才能最终达到效果:
1、.h中:加入函数声明
2、.cpp中加入函数映射
- BEGIN_DISPATCH_MAP(CtestCtrl, COleControl)
- DISP_FUNCTION_ID(CtestCtrl,"display",2223,display,VT_I2,VTS_BSTR)
- END_DISPATCH_MAP()
在此处注意下:DISP_FUNCTION_ID的几个参数:
I、该类的名称
II、类中扩展名同后面的函数名一样,只是多了双引号
III、显示的ID(尽量用大点的,一面和某些ID冲突)
IV、函数名
V、返回值类型:
VI、参数类型
- VT_EMPTY = 0,
- VT_NULL = 1,
- VT_I2 = 2,
- VT_I4 = 3,
- VT_R4 = 4,
- VT_R8 = 5,
- VT_CY = 6,
- VT_DATE = 7,
- VT_BSTR = 8,
- VT_DISPATCH = 9,
- VT_ERROR = 10,
- VT_BOOL = 11,
- VT_VARIANT = 12,
- VT_UNKNOWN = 13,
- VT_DECIMAL = 14,
- VT_I1 = 16,
- VT_UI1 = 17,
- VT_UI2 = 18,
- VT_UI4 = 19,
- VT_I8 = 20,
- VT_UI8 = 21,
- VT_INT = 22,
- VT_UINT = 23,
- VT_VOID = 24,
- VT_HRESULT = 25,
- VT_PTR = 26,
- VT_SAFEARRAY = 27,
- VT_CARRAY = 28,
- VT_USERDEFINED = 29,
- VT_LPSTR = 30,
- VT_LPWSTR = 31,
- VT_FILETIME = 64,
- VT_BLOB = 65,
- VT_STREAM = 66,
- VT_STORAGE = 67,
- VT_STREAMED_OBJECT = 68,
- VT_STORED_OBJECT = 69,
- VT_BLOB_OBJECT = 70,
- VT_CF = 71,
- VT_CLSID = 72,
- VT_VECTOR = 0x1000,
- VT_ARRAY = 0x2000,
- VT_BYREF = 0x4000,
- VT_RESERVED = 0x8000,
- VT_ILLEGAL = 0xffff,
- VT_ILLEGALMASKED = 0xfff,
- VT_TYPEMASK = 0xfff
VI、参数类型
3、CPP中加入函数实现:
4、.idl 文件中还要加相关的接口调度说明
这四个地方加好了就完工了~~