Question

Is there a standard or conventional URI scheme, like file: or http: for referencing objects in a dynamic library?

For example, if I were to represent a function in a library in the form of a unique string that can be used to look up that function (by whatever reflective means), how might I do that?

Specifically I'm developing this in Objective-C, and I assume different languages/platforms will have different representations (I know .NET has its own), but I'm curious about this in a more general sense.

Was it helpful?

Solution

No, the name of the symbol is derived from its name in your code. In windows you will assuming C or C++

HMODULE module=LoadLibrary( [path to your dll] );
//If the exported name is foo.
Function foo=(Function)GetProcAddress(module,"foo");
//Call function
foo();
FreeLibrary(module);

The exported name is compiler-dependent.

Acually such a naming scheme is quite useless. In C++ you can use something like (Note that you will have one FunctionCaller per function prototype)

FunctionCaller("your-dll.dll/foo")();

Where the constructor of FunctionCaller loads the library, calls foo and frees the library. However it is not good because:

  • it may happen that the return value points to a resource inside the library and then will become useless

  • loading libraries and perform function look-up is slow relative to calling the function found

What you do is

  1. Load the library

  2. Load functions that you will need

  3. Use your functions

  4. Free the library

Here you would need to refer to more than one symbol at a time which would require a more complex scheme than uri.

EDIT: If you want to the convenience of calling functions like that you could have a surviving FunctionCaller object that keeps all loaded modules and contains a map from function name to address for each loaded library.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top