使用void指针从库中调用dll的函数 [英] calling functions of dll from library using void pointer

查看:77
本文介绍了使用void指针从库中调用dll的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的:



1)我有一个链接到我的DLL的静态库。

2)Lib有基类,Dll有派生类

3)通过将空指针从dll传递到libarary,是否可以使用Void Pointer在dll中调用适当的函数。 />


在lib中使用基类并在DLL中派生的想法是因为该函数在图书馆中未声明。

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.

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)
}

推荐答案

编辑:当你调用func2(bdll)时,将bdll转换为ALIB *,这只是出于安全问题,因为后来的重构可能会在BDLL的声明中引入多重继承,在这种情况下,即使没有强制转换它也可以工作。在CLIB中,在调用fun1()方法之前将收到的void *转换为ALIB *。
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.


这篇关于使用void指针从库中调用dll的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆