Function pointers and dynamically loaded DLLs

D

Domer

In my program, I load dynamically a DLL and I'm able to get a function
pointer of type "int (__cdecl *)(void)" of any function in the DLL.

If a DLL has a static class function, which calls the constructor and
returns a pointer to the constructed instance of the class, then I don't
have any problems.

However, if a DLL doesn't have such static function, then I can't get it
working. I'm able to get a function pointer to the class constructor,
but I have no idea how to call the constructor in the way that that it
also creates instance of the class (with 'operator new' obviously).
Calling just the constructor, of course, doesn't return a valid instance
of the class.

The header of the DLL is basically like this:
class dllclass
{
public:
__declspec(dllexport) virtual ~dllclass();
__declspec(dllexport) dllclass();

__declspec(dllexport) virtual void dosomething1();
__declspec(dllexport) virtual void dosomething2();
__declspec(dllexport) virtual void dosomething3();
};

I cannot change the DLL, so that kind of workaround isn't possible.

Any suggestions? Is it even possible? Thanks in advance.
 
V

Victor Bazarov

Domer said:
In my program, I load dynamically a DLL and I'm able to get a function
pointer of type "int (__cdecl *)(void)" of any function in the DLL.

If a DLL has a static class function, which calls the constructor and
returns a pointer to the constructed instance of the class, then I don't
have any problems.

However, if a DLL doesn't have such static function, then I can't get it
working. I'm able to get a function pointer to the class constructor, but
I have no idea how to call the constructor in the way that that it also
creates instance of the class (with 'operator new' obviously). Calling
just the constructor, of course, doesn't return a valid instance of the
class.

The header of the DLL is basically like this:
class dllclass
{
public:
__declspec(dllexport) virtual ~dllclass();
__declspec(dllexport) dllclass();

__declspec(dllexport) virtual void dosomething1();
__declspec(dllexport) virtual void dosomething2();
__declspec(dllexport) virtual void dosomething3();
};

I cannot change the DLL, so that kind of workaround isn't possible.

Any suggestions? Is it even possible? Thanks in advance.

It is possible. However, it's not Standard, it's not portable, and it is
all very compiler-specific. Please ask about this in a newsgroup dedicated
to your compiler. If this is VC++, try microsoft.public.vc.language. If
your ISP doesn't carry it, connect to 'msnews.microsoft.com', it's free.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top