Calling Visual Basic DLLs from R, part 2

21/12/2004

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
connectgrowthmod.dll

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

library(SWinTypeLibs)
wood <- LoadTypeLib("c:data
connectgrowthmodels.dll")
getTypeLibTypes(wood)
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:

library(RDCOMClient)
growthmod <- COMCreate("growthmodels.cPlantationModels")
growthmod$ModelCreate(30,11,8,4,0,25,5,5,1000,0,1,2,0,1)
standvol <- growthmod$TreeValue(20)
growthmod$ModelDestroy()

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: