Importing a class at runtime

Started by
6 comments, last by flangazor 19 years, 6 months ago
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?)
Emil Johansen- SMMOG AI designerhttp://smmog.com
Advertisement
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?
Emil Johansen- SMMOG AI designerhttp://smmog.com
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.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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.
Emil Johansen- SMMOG AI designerhttp://smmog.com
I know I have read about this being done, perhaps even here, I just can't find it. :(
Emil Johansen- SMMOG AI designerhttp://smmog.com
Sorry, but I'm not entirely sure what your after here. Could you provide an example?
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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