Calling Visual Basic DLLs from R, part 2


After yesterday’s experience calling other software from R, refractionist I continued working to connect to my DLL. I first registered my DLL as a COM server in windows typing in the command line:

regsvr32 c:data

Then I had a look at my DLL using the SWinTypeLibs library, visit this site typing in R:

wood <- LoadTypeLib("c:data
DLLFuncs <- getFuncs(wood[[1]])
DLLElements <- getElements(wood[[1]])

The command getTypeLibTypes(wood) showed that the DLL contained _cPlantationModels (of type dispatch) and cPlantationModels (of type coclass). That is why I then continued working with wood[[1]], herpes of type dispatch.

After that I needed help from Tim. He had compiled the DLL leaving the class module cPlantationModels with an instancing of type 5 (multiUse), making it available for outside users. Connecting to the library was relatively straightforward with Tim’s help:

growthmod <- COMCreate("growthmodels.cPlantationModels")
standvol <- growthmod$TreeValue(20)

This code loaded the RDCOM client library, created a connection to the DLL, instantiated a growth model with starting values, evaluated the model and destroyed the instantiation. Now we are ready to start testing the models from inside R.

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 say:

    [...] Freedom and legal action Calling Visual Basic DLLs from R, part 2 [...]

Write a comment: