Importing a class at runtime
I'd like my application to load a compiled class from an external file into memory and call a function from it, giving the this pointer as parameter so that the loaded class may call some functions from its parent class.
The loaded class will only communicate with the rest of the application via function calls to the parent class so I shouldn't have any memory errors like referring to global variables directly, but are there any other issues that I should be aware of? And how is this done best? (aka. have any of you dont this before?)
well you didn't mention which language your using, i'll assume c++ dynamic class loading is a breeze in some other lanaguage they support as standard but not the case for c++ you'll have to write one this can help you or use third-party library such as this.
Woops! My bad. Yeh I am indeed using C++.
I just went over the first article quickly and noticed that Linux is mentioned. This isn't platform specific is it?
I just went over the first article quickly and noticed that Linux is mentioned. This isn't platform specific is it?
The 4 dl*() functions are linux specific, but the general principle still holds under windows. The equivalent windows functions are
dlopen() = LoadLibrary()
dlsym() = GetProcAddress()
dlerror() = GetLastError()
dlclose() = FreeLibrary()
Check out MSDN for more details on these functions.
dlopen() = LoadLibrary()
dlsym() = GetProcAddress()
dlerror() = GetLastError()
dlclose() = FreeLibrary()
Check out MSDN for more details on these functions.
The idea was to have the compiled class in an external file, copy it to the memory and then use it. I have used dll's many times before but thats now what I want in this case.
You can generate classes at runtime if you brew your own metaobject protocol. It's not a precompiled class, but your problem looks as though it could be solved using this strategy.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement