7 Replies Latest reply on Jul 17, 2009 5:08 AM by EJP

    How to use .OCX properties using java??

    843829
      Hi All,

      I connected the OCX(ActiveX) component of the program using JACOB by giving the classid from the registry.

      public static void main(String[] args)
      {
      ActiveXComponent ie = new ActiveXComponent("clsid:86C16A54-40A2-47EC-95B8-94E36701B0B9");
      Object ieo = ie.getObject();
      System.out.println(ieo);

      Output is : com.jacob.activeX.ActiveXComponent@4e42c917

      The next line is to set the property::

      ie.setProperty("PrinterName", new Variant("Image Service"));

      It gives the error � exception ::

      Error:

      Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
      At Invoke of: PrinterName
      Description: Catastrophic failure

      at com.jacob.com.Dispatch.invokev(Native Method)
      at com.jacob.com.Dispatch.invokev(Dispatch.java:391)
      at com.jacob.com.Dispatch.invoke(Dispatch.java:274)
      at com.jacob.com.Dispatch.put(Dispatch.java:374)
      at com.jacob.activeX.ActiveXComponent.setProperty(ActiveXComponent.java:69)
      at string1.main(string1.java:20)

      PrinterName is the specified property of the OCX.

      If we are giving the name other then specified in the OCX then it gives different error:

      Exception in thread "main" com.jacob.com.ComFailException: Can't map name to dispid: Unknown
      at com.jacob.com.Dispatch.invokev(Native Method)
      at com.jacob.com.Dispatch.invokev(Dispatch.java:391)
      at com.jacob.com.Dispatch.invoke(Dispatch.java:274)
      at com.jacob.com.Dispatch.put(Dispatch.java:374)
      at com.jacob.activeX.ActiveXComponent.setProperty(ActiveXComponent.java:69)
      at string1.main(string1.java:20)

      It proves that the OCX is connected.

      Don�t know how to use the properties or method of that OCX????

      Pls mail me�at krunalbarot@gmail.com

      Thanx in advance.



      Regards,
      Krunal Barot,
        • 1. Re: How to use .OCX properties using java??
          843829
          Hi there's a bit of code that I used and worked fine in my case. To set a variable I'd recomend you to use "Dispatch.put" instead of "setProperty"


          private static ActiveXComponent      myComponent;
          private static Dispatch           myObject;

          MyComponent = new ActiveXComponent("clsid:XXXXXXXX");
          MyObject = MyComponent.getObject();


          //For setting and requesting properties
          Dispatch.put( myObject, "Property", new Variant( new Integer (1024)));
          //Now I want to check the set parameter
          Variant vResultmine = Dispatch.call( myObject, "Property");
          System.out.println("Property "+vResultmine.toString());

          //This line makes "IOvar" to be a read-write String variable (the OCX will be able to put data on it)
          Variant IOvar = new Variant(new String(""), true); //false will is used by default, in this case variables can not be written

          //Next we invoke the method. In this case the method needs 2 String parameters and puts the result on a third variable (IOvariable)
          Variant vResult = Dispatch.call(myObject, "Method",
               new Variant((String)"first_parameter"),     
               new Variant(("second_parameter")),
               IOvar);     

          //Now I print the obtained value
          TheIOvar=IOvar.toString();
          System.out.println("TheIOvar "+TheIOvar);

          By the way, for questions regarding JACOB you can also check JACOB's forums too: http://sourceforge.net/forum/forum.php?forum_id=375946

          Hope this helps
          N
          • 2. Re: How to use .OCX properties using java??
            843829
            hi,

            Thanks a lot for the reply but i am still getting the same error as stated earlier Catastrophic failure????
            • 3. Re: How to use .OCX properties using java??
              843829
              Perhaps the parameter you are using is not correct at all (the rest of your code seems fine to me). Anyway you'd better check JACOB forum. You'll find much more help on this issue there.
              • 4. Re: How to use .OCX properties using java??
                843829
                ok Thnx a lot !!! :)
                • 5. Re: How to use .OCX properties using java??
                  843829
                  Following your advise I am using

                  Variant IOvar = new Variant(new String(""), true);

                  for getting results from EnumKey method of StdRegProv in WMI:

                  Variant ret = Dispatch.call(oReg, "EnumKey", HKEY_LOCAL_MACHINE, strKeyPath,IOvar );
                  out.println("EnumKey: HKEY_LOCAL_MACHINE\\"+strKeyPath+"="+var +"arrSubKeys="+IOvar.toString()+"<BR>");

                  The output is:

                  EnumKey: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC=0arrSubKeys=?

                  How to enumerate IOvar then?

                  Thanks
                  • 6. Re: How to use .OCX properties using java??
                    843829
                    Hi,

                    How did you resolve this error?

                    Thanks
                    Suja
                    • 7. Re: How to use .OCX properties using java??
                      EJP
                      Pls mail me&#65533;at ...
                      Certainly not. Any answers should be posted here. That's what these forums are for. This is not a personal coding service. I am blocking your post partly for that reason and partly because you have publicly disclosed an email address, which is a very poor practice unless you like spam.