Sign in to follow this  
Kackurot

geting class functions in dll

Recommended Posts

Kackurot    122
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 this post


Link to post
Share on other sites
moeron    326
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 case
class EXPORT FullyExportedClass
{
public:
FullyExportedClass(void);
~FullyExportedClass(void);
};

// in this case you would export whichever functions you want to be
// available outside the dll
class 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 included
class 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 this post


Link to post
Share on other sites
Kackurot    122
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 this post


Link to post
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 this post


Link to post
Share on other sites
Kackurot    122
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this