Quantum Forest logs are written by Luis A. Apiolaza in Christchurch, New Zealand.
« previous post · next post »
After yesterday’s experience calling other software from R, 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\rconnect\growthmod.dll
Then I had a look at my DLL using the SWinTypeLibs library, typing in R:
library(SWinTypeLibs)
wood <- LoadTypeLib("c:\\data\\rconnect\\growthmodels.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]], 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.
PS. 2005-02-03. I have added information on COM servers for R in my post Calling R from Visual Basic (link to Quantum Forest).
אאא