By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

Function pointers and dynamically loaded DLLs

P: n/a
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.

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Domer" <do***@domer.domer> wrote...
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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.