(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-03-24 12:24 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - Plugin? New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
Smallhacker

Super Koopa
I AM A Group Of Officially Frustrated Younglings, G.O.O.F.Y. MEMBER








Since: 11-17-05
From: Söderhamn, Sweden

Last post: 6285 days
Last view: 6283 days
Skype
Posted on 02-10-07 12:34 AM Link | Quote
I've been thinking about how to make plugin systems recently... After some thinking and searching, it seems like run-time linked DLL files are perfect for doing this.

However, run-time linked DLL is a Windows feature, and that made me wonder about something.

How would one make a plugin system that follows these rules?
1) It works on any system, not only on Windows.
2) It isn't a script system. (That would be like a billion times slower)
3) It isn't an external program that modifies the original program's RAM memory.
4) It's made in C++.

...is such a plugin system even possible?
niteice

Gator


 





Since: 08-15-06
From: Connecticut

Last post: 6283 days
Last view: 6283 days
Posted on 02-10-07 03:16 AM Link | Quote
Yes. You just need to recompile the plugins and write a new loader for each operating system that the host program runs on. Nearly trivial.
Guy Perfect









Since: 11-18-05

Last post: 6285 days
Last view: 6284 days
Posted on 02-10-07 03:17 AM Link | Quote
That's what he wants to know how to do, niteice.
niteice

Gator


 





Since: 08-15-06
From: Connecticut

Last post: 6283 days
Last view: 6283 days
Posted on 02-10-07 03:36 AM Link | Quote
Oh...silly me...

On Windows, you have LoadLibrary, GetProcAddress, and FreeLibrary. On pretty much everything else (I assume you'd only be interested in Linux/BSD and OS X), you have dlopen, dlsym, and dlclose. They all work pretty much the same way:

Windows:

HMODULE lib;
void *func; // you might want to typedef this to the specific function call you're making to the dll

lib = LoadLibrary("plugin.dll");
func = GetProcAddress(lib, "someFunction");
FreeLibrary(lib);


Unix:

void *lib
void *func; // you might want to typedef this to the specific function call you're making to the dll

lib = dlopen("plugin.so", RTLD_NOW);
func = dlsym(lib, "someFunction");
dlclose(lib);



(edited by niteice on 02-09-07 09:38 PM)
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6284 days
Last view: 6284 days
Posted on 02-10-07 06:33 AM Link | Quote
Yep, I made a simple plugin system using that method, it works well. You can even give each plugin its own thread and set up an exception handler so it won't take out your entire program if it crashes. There's also some way (LoadLibraryEx()?) to load the DLL without calling DLLMain() or whatever the function is that gets called at unload, which allows you to load the plugin without it being able to execute any code yet; this is generally a good thing as it ensures buggy, malicious or poorly designed plugins won't be able to cause trouble (even something as simple as malloc()ing a huge buffer could be trouble) until they're actually executed. In a cross-platform system obviously you won't be using these functions anyway.

Also, you can put a resource in the DLL containing information such as the plugin's name, version, etc and read it out from your program. Not sure how you'd do this on other platforms though.
Guy Perfect









Since: 11-18-05

Last post: 6285 days
Last view: 6284 days
Posted on 02-10-07 07:17 AM Link | Quote
I see no reason you can't just define a function in the library like "GetLibraryInfo" or the like which will return its version, author, release date, etc.
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6284 days
Last view: 6284 days
Posted on 02-10-07 09:07 AM Link | Quote
Depends what you want to do and how paranoid you are. Someone could write a plugin that just closes the program when this function is called. This could easily render your program useless unless you were to delete the plugin, and past experience tells me that instructing someone how to find and delete a file can be unpleasant. Using a resource, no code is executed, so for example the user can view a list of installed plugins and just remove the unwanted one right there.

I'm probably being overprotective when I do it this way, since I tend to think of plugin hosts as mini operating systems, and it'd be silly for an OS to run a program and trust it to supply some static information, when that information could simply be placed in a standardized location and read out of the file directly. In any case, what works works.
Smallhacker

Super Koopa
I AM A Group Of Officially Frustrated Younglings, G.O.O.F.Y. MEMBER








Since: 11-17-05
From: Söderhamn, Sweden

Last post: 6285 days
Last view: 6283 days
Skype
Posted on 02-11-07 12:39 AM Link | Quote
Aha. Thank you.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - Plugin? |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.036 seconds; used 382.98 kB (max 463.59 kB)