java调用ocx方法

来源:互联网 发布:企查查同类软件 编辑:程序博客网 时间:2024/05/20 17:40

一、注册.ocx控件,在命令窗口运行:regsvr32.exe  XXX.ocx,

二、取得控件的classid,开始-->运行-->输:regedit,打开注册表---->在注册表的工具栏的编辑中找到搜索按钮,输入XXX.ocx的名字XXX查找,就可以得到控件的classid,


即工程1.UserControl1:

三、

OLE调用的关键代码:

                 Display display = new Display();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
OleControlSite site = new OleControlSite(frame, SWT.NONE, "工程1.UserControl1");
OleAutomation auto = new OleAutomation(site);
    调用控件中的方法:

//stNum为.ocx中要调用的方法名

             int[] ids = auto.getIDsOfNames(new String[]{"setNum"});
            Variant rtnv = auto.invoke(ids[0], new Variant[]{ new Variant(1) , new Variant(4)}); 




0 0
原创粉丝点击