OCam'OLE is an OLE binding for OCaml. OLE is a COM-based technology that enable Automation. Automation is a way to create and manipulate remote objects or applications that exposes COM interfaces.
To take an easy example, Excel, Word and most of today's big applications installed on your computer can be controled by an Automation client. Visual Basic is such a client, and can control an Excel application (this is called "scripting"). Now with OCam'OLE, you can do the same, with the additional feature of type-safe operations ( by using OLEGen ) !
How does it works ?
Each OLE application have a Type-Library that contains list of objects. Each object have a list of methods with type information on arguments and returned values. OCam'OLE enable the browsing of such Type-Libraries for any application.
What is OLEGen ?
OLEGen is an ocaml program that is using OCam'OLE to browse Type-Libraries and generate the corresponding ML/MLI code. The code generated this way is hidding OCam'OLE usage to call methods and is then providing a type-safe interface to manipulate objects.
OCam'OLE features :
- raw support of IDispatch, ITypeInfo, ITypeLib
- conservative VARIANT C/Caml conversions
- remote calls via IDispatch.Invoke
- static interface generation with OLEGen
The current distribution include a sample that demonstrate the combined usage of OCam'OLE and OLEGen to enable the creation and the control of an Excel sheet in a few lines of OCaml code.
To install this program, you need :
- ocaml 3.04 or better
- MSVC compiler & linker & nmake
- Excel installed to try the sample
The following files are included in the sources :
ocamole.cpp: C stubs for OCamole
ocamole.ml: OCaml OLE interface
olegen.ml: OLEGen sources
excel1.ml: an Excel manipulation sample based on the generation of the Excel module with OLEGen
To install, simply run "NMAKE" is the directory where you have put OCam'OLE. This will generate the following files :
ocamole.dll + ocamole.cma: the OCam'OLE binaries
olegen.exe: OLEGen binary, run it to get some help
excel.cma: the Excel ocaml library
excel1.exe: run it to test Excel control with OCaml
If you're experiencing some problems, check the following environnement variables on your system :
PATH: must include your Visual Studio /BIN directory
LIB: must include Visual Studio /LIB directory and your OCaml distribution /LIB directory
INCLUDE: must include Visual Studio /INCLUDE directory and your OCaml distribution /LIB directory
If you don't have Excel installed, you can run "NMAKE NOSAMPLE" to build only OCam'OLE & OLEGen binaries.
How do I use it ?
You can now do the following :
- use "raw" Automation by directly using OCam'OLE
- first generate ML/MLI code for the application you want to use by using OLEGen and then watch the generated MLI to manipulate it.
Licence / Authors / Copyrights
OCam'OLE and OLEGen are under GPL.
Contact the author for more informations
Thanks to Jean-Marc Eber & Xavier Leroy.
And especially to Lexifi for supporting this project.
To access the sources of this project, you can check them out from CVS repository. This is recommanded since this way you'll be sure to get latest version with fixes. Use the following commands :
cvs -d:pserver:firstname.lastname@example.org:/cvsroot login (enter empty password) cvs -d:pserver:email@example.com:/cvsroot co ocaml/ocamole
Other way is to download a source ZIP here.