Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is what i am trying to do:

1) I have a static library that is linked to my DLL.
2) The Lib has Base Class, Dll has the derived class
3) By Passing a void pointer from dll to libarary, is it possible to call appropriate function in the dll using the Void Pointer.

The idea of having base class in lib and derived in DLL, is because the function will be undeclared in the libarary.
C++
class ALIB // Base class  - in Libarary testlib.lib
{
  virtual fun1() =0;
}

class CLIB
{
   func3(void *bdll);
   bdll->fun1();
}

class BDLL:public ALIB      //Derived class - in DLL testdll.dll,The testlib.lib is linked to testdll.dll
{                                    
  fun1()
  {
    //Implemented
  }  
}

class DDLL
{
   BDLL *bdll;
   func2(bdll)
}
Posted
Updated 7-Aug-13 4:32am
v2

1 solution

EDIT: when you call func2(bdll) cast bdll to an ALIB*, this is just for safety issue because later refactorization may introduce multiple inheritance in the declaration of BDLL, in this case it would work even without the cast. In CLIB cast the received void* to an ALIB* before calling the fun1() method.
 
Share this answer
 
v2
Comments
gssajith87 7-Aug-13 9:22am    
Hi Thanks for your reply,
I don't think this will work, even the problem i am having now is that,

I have a void pointer that is passed to the library and i need to cast the void pointer in the library.

As you have mentioned, even if i have the interface class in the library and the definition in the dll, will it be possible to call the function defined in the dll from library by casting the void pointer in the library ?

Note: The library is linked to the dll
pasztorpisti 7-Aug-13 9:54am    
If you have to use a void* to pass info the lib then you can pass a CMyInterface* as void pointer and then in the lib you can cast it back to CMyInterface*. However I would pass CMyInterface* directly if possible since it is a know type by both the lib and the dll.
pasztorpisti 7-Aug-13 10:38am    
I was lazy to read the ugly source code but it has been formatted since then so I checked it and modified my answer accordingly. BTW, why dont you receive an ALIB* parameter instead of a void* in func3???
gssajith87 8-Aug-13 4:03am    
Thanks, I directly changed it from void to ALIB* and it works, even passing void pointer as you have mentioned earlier is working.
pasztorpisti 8-Aug-13 5:34am    
Nice. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900