Archived

This topic is now archived and is closed to further replies.

How to write smart functions for your dll

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering what the best way is to write a dll with as little effort and maintenance needed as possible. What I mean is: Imagine a dll exporting many hundreds functionalities and having many dozen functionalities added every few month. How to keep backward compatibility? (people using an old version of your dll can simply replace it with the newer version and everything is still working without having to recompile) How not to get messed up with the function names? I need some advice but here is how I am doing it: I have a limited amount of functions (around 20). These functions''s names reflect the arguments they are taking a bit like openGL. For example I have: xxxipfpc(int command,int a,float* pf,char* pc) Every function takes a command (there are many hundreds of commands) first which tells the function what to do. The commands are enumerated like this: enum {renderScene=0,changeColor,displayText,... } Am I going in the right direction???

Share this post


Link to post
Share on other sites
That could work i suppose, although you would have to ensure that the entry point to the exported functions remained the same if you wanted people to be able to link to it with lib files.

For another possible way of doing it see the section on run time linking in this article:

http://www.gamedev.net/reference/articles/article928.asp


[edited by - Grambo on July 23, 2002 4:16:07 AM]

Share this post


Link to post
Share on other sites
You could also extend that so that you can pass a version number to the function, and it will return the correct class. That way, you can have several version (or even objects) created from the same function.

Steve
DirectX Programmer
Soon to be the new Bill Gates

Share this post


Link to post
Share on other sites
2 things:
1. you CANT staticly link to the dll. you MUST use LoadLibrary() and GetProcAddress(). no exceptions, otherwise no matter the system you need to recompile.

2. basically you set up a versioning system. you create a base struct which is version one. it contains pointers to all functions. as you add more, you make the struct bigger. eariler apps wont even know it, and newer apps will get an error if they try to pass a version higher then supported by the dll.

a better way would be to use a base class which gets extended since its looks cleaner and allows you to keep multiple versions of the same function (so if you extend a function so its very different, the old code dont get trampled yet you ont need new function names). basically you need to look at how COM works on a basic level. its the syle your looking for (ie how DirectX works). you may even wish to try out directx so you can see COM in action.

the comand method you suggets requires too much overhead and is limited. its also very error prone. what if a fucntion needs a specilized struct? sure you could start with type casting or adding functions, but things get hairy quite quickly. plus i know i would hate to have xxxipfpc() calls littered all over the place instead of real function calls with return values and such.

Share this post


Link to post
Share on other sites