geting class functions in dll

Recommended Posts

Does anyone know how to retrive class functions from dll? I need to know how to retrieve class functions from a dll, but I don't know the syntax. Its easy for me to get none class functions using GetProcAddress. If anyone knows, can you please show me an example of it. thanks

Share on other sites
if the functions are exported then you just need to instantiate an instance of the class and call them like you would any other...If they are not exported then there is nothing you can do to use them and you will get linker errors, unless they are inlined in the header file.

this following is an example (assuming MSVC)
// some dll's header file#ifdef _WINDOWS#   ifdef THISDLL_EXPORTS #      define EXPORT __declspec(dllexport)#   else#      define EXPORT __declspec(dllimport)#   endif#else#   define EXPORT#endif// all functions will be exported in this caseclass EXPORT FullyExportedClass{public:   FullyExportedClass(void);   ~FullyExportedClass(void);};// in this case you would export whichever functions you want to be // available outside the dllclass PartiallyExportedClass{   public:     EXPORT PartiallyExportedClass(void);     EXPORT ~PartiallyExportedClass(void);   private:     void NoneExportedFunction(void);};// if everything is inlined then the functions will be visible// anywhere this header is includedclass FullyInlinedClass{    public:       FullyInlinedClass(void)       {         //etc...       }       ~FullyInlinedClass(void)        {        }};

In cases where the stuff is not inlined (most cases) you need to link to the dll's lib file while compiling and make sure the dll file is in the same directory as, or in a path directory, for your executable/dll to access it.

Share on other sites
Umm... I wanted to know how to get them dynamicly. I already know that method, the one u are showing me. I want to call getprocadress and get them that way. So if u know how to do it that way,please let me know.

Share on other sites
Here you have a good article for run time linking dlls.

Share on other sites
Just a summary of the above:
You can't. (get class functions)
You can only get a class instance from a DLL. You do this by having both your application and the dll having the same ABC, which will define the functions you can use. They (the plugin makers) will derive off this ABC and provide it to your application through a C function that you get using GetProcAddress that will create their derived class.

For more in depth information, see the link frecco2k put up.

Share on other sites
Ok, thanks thats what I figured, just stuck with one more about geting functions. What if the function was in a namespace, how would u get them, or can u ? I was writing a math lib that had math namespace and a math_SIMD name space. So is there a way to get them from namespaces or do I just have to forget about that idea?

Create an account

Register a new account

• Forum Statistics

• Total Topics
628278
• Total Posts
2981785

• 10
• 11
• 17
• 13
• 9