Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function pointers and dynamically loaded DLLs

Reply
Thread Tools

Function pointers and dynamically loaded DLLs

 
 
Domer
Guest
Posts: n/a
 
      02-21-2005
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.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-21-2005
"Domer" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
DLLs being loaded for all applications Rich Windows 64bit 0 03-06-2010 03:49 PM
help using windows dlls and pointers dafritz@gmail.com Ruby 6 04-21-2006 05:07 PM
How to determine DLLs loaded in 64bit process from a 32bit process? Pieter Windows 64bit 11 06-12-2005 04:34 PM
Re: how to programatically give assembly loaded from network the same trust as those loaded from local host? Marcelo Birnbach [MS] ASP .Net 0 06-27-2003 11:51 PM



Advertisments