[R] Calling Windows DLL using .C; function name not known but in exports.

Duncan Murdoch murdoch.duncan at gmail.com
Sun Jan 22 02:40:55 CET 2012


On 12-01-20 10:05 AM, Alex van der Spek wrote:
> First time ever that I try to call subroutines in a Win DLL using R.
> Have done this before using VBA and Python.
>
> The C code's function argument list contains only double pointers
> (double *x). The function is declared void, the output value is one of
> the arguments.
> C calling sequence is used.
>
> When inspecting the exports of the DLL with dumpbin I can see that the
> function I need is exported under the name 'planckwR'.
>
> Loading the DLL with dyn.load(dllpath). Works fine. getLoadedDLLs()
> shows info on the 'Planck.dll' that I made. So far so good.
>
> Made a function i R like this:
>
> Planckw<-function(Temp) {
>       wavelength<-0.0
>       .C('planckwR',as.double(Temp),as.double(wavelength))
>       return(wavelength)
> }

That will return 0.0 once you get the name sorted out; .C won't modify 
the variable wavelength, it will return new values in a list.

>
> Calling this function, R complains the function 'planckwR' is not in the
> DLL.

I would look in the export table printed by objdump -x to check this.  I 
don't know the dumpbin utility.
>
> This baffled me as I can see it in the exports table using dumpbin.
>
> I use Visual C++ 97 compiler. Old but works. It does change the FPU
> control word, which I know it should not. Working on that one too. Any tips?

Use gcc?

Duncan Murdoch

>
> Any help much appreciated.
> Alex van der Spek
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list