Call COM object

From CodeCodex

Implementations[edit]

Java[edit]

com4j A Java library that allows Java applications to seemlessly interoperate with Microsoft Component Object Model. First generate Java type definitions from a COM type library. Here we are doing for the type library for the Windows Scripting Host.

> java -jar tlbimp.jar -o wsh -p test.wsh %WINDIR%\system32\wshom.ocx

Then we are able to call WSH objects/methods.

public class Main {
  public static void main(String[] args) {
    IFileSystem3 fs = ClassFactory.createFileSystemObject();
    for( String file : args )
      System.out.println(fs.getFileVersion(file));
  }
}

https://com4j.dev.java.net/

j-interop Implementation of DCOM wire protocol (MSRPC) to enable development of Pure Bi-Directional, Non-Native Java applications which can interoperate with any COM component. The implementation is itself purely in Java and does not use JNI to provide COM access. http://sourceforge.net/projects/j-interop

j-xchange Pure java implementation of the entire Collaboration Data Objects (CDO 1.21) library for accessing Microsoft Exchange Server in a platform independent manner. http://sourceforge.net/projects/j-xchange/

Tcl[edit]

# Call Excel COM object, open an xls file and get the content of C7
package require tcom
set app [::tcom::ref createobject "Excel.Application"]
set app [::tcom::ref getobject "C:/test.xls"]
set ws [$app Worksheets]
set xlCellTypeLastCell 11
set cells [$ws Cells]
set C7 [[$cells Item 7 C] -get Value]
# Call Internet Explorer COM object and go to a web site
package require tcom
set ie [::tcom::ref createobject InternetExplorer.Application.1]
$ie Visible True
$ie Navigate "http://www.tcl.tk/"

See also this HowTo for an alternative package to access a COM package from Java. |