Function pointers and dynamically loaded DLLs

Discussion in 'C++' started by Domer, Feb 21, 2005.

  1. Domer

    Domer Guest

    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.
    Domer, Feb 21, 2005
    #1
    1. Advertising

  2. "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
    Victor Bazarov, Feb 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcelo Birnbach [MS]
    Replies:
    0
    Views:
    3,309
    Marcelo Birnbach [MS]
    Jun 28, 2003
  2. Udo Corban
    Replies:
    0
    Views:
    3,827
    Udo Corban
    Jan 23, 2004
  3. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    657
  4. Replies:
    6
    Views:
    253
    dafritz
    Apr 21, 2006
  5. Replies:
    5
    Views:
    103
Loading...

Share This Page