Visual Basic ActiveX control can't access properties and methods at run time -
i have simple activex control have 4 properties , 8 methods set , get, problem can't access them @ runtime , @ desin time works fine below error message occur when lanch programm in visual basic
, dispatch map file.idl of activex control. in visual c++ have message "member not found" when access propertys or methods. can me problem. in advance.
an unhandled exception of type 'system.runtime.interopservices.comexception' occurred in mscorlib.dll additional information: catastrophic failure (exception hresult: 0x8000ffff (e_unexpected))
csliderctrl1.cpp file has dispatch map
begin_dispatch_map(csliderctrl1, colecontrol) disp_property_ex_id(csliderctrl1, "backgroundcolor", 1, getbackgroundcolor, setbackgroundcolor, vt_i4) disp_property_ex_id(csliderctrl1, "backcolor", 2, getbackcolor, setbackcolor, vt_i4) disp_property_ex_id(csliderctrl1, "forecolor", 3, getforecolor, setforecolor, vt_i4) disp_property_ex_id(csliderctrl1, "positionbar", 4, getpositionbar, setpositionbar, vt_i4) end_dispatch_map()
slider.idl file
include
include
[ uuid(f9248e73-f5ad-43b1-815b-91817e91b537), version(1.0), control ] library sliderlib { importlib(stdole_tlb);
// primary dispatch interface csliderctrl1 [ uuid(093c2cb6-c812-4b91-84cb-1c508439dbfd) ] dispinterface _dslider { properties: [id(1)] colorref backgroundcolor; [id(2)] colorref backcolor; [id(3)] colorref forecolor; [id(4)] unsigned long positionbar; methods: [id(5)] colorref getbackgroundcolor(); [id(6)] void setbackgroundcolor([in] colorref color ); [id(7)] colorref getbackcolor(); [id(8)] void setbackcolor([in] colorref color); [id(9)] colorref getforecolor(); [id(10)] void setforecolor([in] colorref color); [id(11)] unsigned long getpositionbar(); [id(12)] void setpositionbar([in] unsigned long position); }; // event dispatch interface csliderctrl1 [ uuid(9113aa84-629f-4c34-88a3-ebfff0f94b2e) ] dispinterface _dsliderevents { properties: // event interface has no properties methods: }; // class information csliderctrl1 [ uuid(fa933e84-1b30-4283-9a2a-9cc1e8d99408), control ] coclass slider { [default] dispinterface _dslider; [default, source] dispinterface _dsliderevents; };
};
finally found way, code in visual basic must be
dim slider new object
slider = axslider1.getocx
slider.setbackgroundcolor(100000)
begin_dispatch_map(csliderctrl1, colecontrol) disp_function_id(csliderctrl1, "getbackgroundcolor",1, getbackgroundcolor,vt_ui4,vts_none) disp_function_id(csliderctrl1, "setbackgroundcolor",2, setbackgroundcolor, vt_empty,vts_ui4 ) disp_function_id(csliderctrl1, "getbackcolor",3, getbackcolor, vt_ui4, vts_none) disp_function_id(csliderctrl1, "setbackcolor", 4,setbackcolor, vt_empty, vts_ui4) disp_function_id(csliderctrl1, "getforecolor",5, getforecolor,vt_ui4, vts_none) disp_function_id(csliderctrl1, "setforecolor", 6,setforecolor, vt_empty, vts_ui4) disp_function_id(csliderctrl1, "getpositionbar",7, getpositionbar,vt_ui4, vts_none) disp_function_id(csliderctrl1, "setpositionbar", 8,setpositionbar, vt_empty, vts_ui4) disp_property_ex_id(csliderctrl1, "backgroundcolor", dispidbackgroundcolor, getbackgroundcolor, setbackgroundcolor, vt_ui4) disp_property_ex_id(csliderctrl1, "backcolor", dispidbackcolor, getbackcolor, setbackcolor, vt_ui4) disp_property_ex_id(csliderctrl1, "forecolor", dispidforecolor, getforecolor, setforecolor, vt_ui4) disp_property_ex_id(csliderctrl1, "positionbar", dispidpositionbar, getpositionbar, setpositionbar, vt_ui4) end_dispatch_map()
Comments
Post a Comment