jjunju
jjunju

Reputation: 527

How to get list of functions inside a DLL loaded into R using dyn.load

A few years ago I wrote a dll with some functions for running a hydrological model. I have forgotten the names and arguments of the functions inside the dll and unfortunately I forgot to write a good documentation file. The functions were complicated so I don't want to go through the alternativs I could have used that entail rewriting the code.

I have loaded my dll into R but as I said, I neither recall the names nor the syntax of the functions.

How can I list the functions and how can i get to see the syntax of the functions and the arguments I am supposed to provide? I know that the arguments were common model inputs but honestly I dont remember the formats.

In addition loading the dll doesn't give an error but checking if it's loaded gives a FALSE. How can I fix this?

> x<-dyn.load("hbv_R64.dll")
> is.loaded("hbv_R64")
[1] FALSE

Upvotes: 5

Views: 2509

Answers (2)

Joshua Ulrich
Joshua Ulrich

Reputation: 176668

is.loaded("hbv_R64") would only return TRUE if hbv_R64.dll had a symbol (function) named hbv_R64.

You can get a list of the registered name (not necessarily the name in the source code) and the interface by using getDLLRegisteredRoutines.

R> dlls <- getLoadedDLLs()
R> getDLLRegisteredRoutines(dlls$base)
                   .Call .Call.numParameters .Fortran .Fortran.numParameters
1      R_addTaskCallback                   4    dqrcf                      8
2 R_getTaskCallbackNames                   0   dqrdc2                      9
3   R_removeTaskCallback                   1   dqrqty                      7
4                                               dqrqy                      7
5                                              dqrrsd                      7
6                                               dqrxb                      7
7                                               dtrco                      6

In your case:

x <- dyn.load("hbv_R64.dll")
getDLLRegisteredRoutines(x)

?getDLLRegisteredRoutines says, "In the future, we will provide information about the types of the parameters also." So that information could already be accessible, though I'm not sure how.

Upvotes: 6

Dragos Pop
Dragos Pop

Reputation: 458

Best solution: use a disassembly.

It is easy to read the functions with a tool( http://www.nirsoft.net/utils/dll_export_viewer.html for example), but it's hard to find the parameters.

Upvotes: -1

Related Questions