Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/zentree/uncronopio.org/quantum/textpattern/lib/txplib_db.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /home/zentree/uncronopio.org/quantum/textpattern/lib/txplib_db.php:26) in /home/zentree/uncronopio.org/quantum/textpattern/publish.php on line 43

Warning: Cannot modify header information - headers already sent by (output started at /home/zentree/uncronopio.org/quantum/textpattern/lib/txplib_db.php:26) in /home/zentree/uncronopio.org/quantum/textpattern/publish.php on line 44

Warning: Cannot modify header information - headers already sent by (output started at /home/zentree/uncronopio.org/quantum/textpattern/lib/txplib_db.php:26) in /home/zentree/uncronopio.org/quantum/textpattern/publish.php on line 425
Luis Apiolaza .:. Quantum Forest: Calling Visual Basic DLLs from R, part 2

Quantum Forest logs are written by Luis A. Apiolaza in Christchurch, New Zealand.

Search

Topics

Non-blog (Wiki)

Somewhere else

« previous post · next post »

Calling Visual Basic DLLs from R, part 2
Published Wednesday December 22, 2004 · Permalink

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).

אאא

Quantum Forest Home