Calling Visual Basic DLLs from R


I want to test a series of growth models that are part of a DLL(Dynamic Link Library) written in Visual Basic. Although I could write several pieces of code in VB to test the library, check I will try to access it from R. In this way I can run simulations and then process the results from within a statistical package.

I obtained the RDCOM client and the SWinTypeLibs facilities from the Omega Hat Project for Statistical Computing. If you are running R 2.0 you should get the latest compilations from here (, view 11-Oct-2004, 12:08, 433K and, 11-Oct-2004, 12:09, 147K).

It is possible to learn about the classes, methods, parameters and return types of a COM server using the SWinTypeLibs library. Once we have learn about the server, we can access it using the RDCOMClient (this is explained in this presentation in PDF format, 50KB). For example:

ie = COMCreate("InternetExplorer.application")
ie[["Visible"]] <- TRUE\

will load the library, connect to Internet Explorer, display the window and point the browser to Quantum Forest. An example using Excel would be:

exc <- COMCreate("Excel.Application")
exc[["Visible"]] <- TRUE\
books <- exc[["Workbooks"]]
actsheet <- books[[1]][["ActiveSheet"]]
myrange <- actsheet$Range("A1:C10")
myrange[["Value"]] <- asCOMArray(matrix(rnorm(30, 10, 3)))

This will connect to Excel, show the program, get a list of workbooks, add one, get which sheet is active, define a range and fill it with N(0,1) random numbers.

I continue exploring the package to see if I can connect to my own DLL.

Filed in programming, software, statistics

There is 1 comment in this article:

  1. 12/01/2008Quantum Forest » Blog Archive » Calling Visual Basic DLLs from R, part 2 say:

    [...] Calling Visual Basic DLLs from R Resucitating Quantum Forest [...]

Write a comment: