DLL加载和调用类方法 [英] DLL load and call class method

查看:73
本文介绍了DLL加载和调用类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在VC ++中加载DLL和调用函数,我们使用LoadLibrary和GetProcAddress,它们需要方法的错误名称。它会实例化一个类对象然后调用该方法吗?

To load a DLL and call function in VC++, we use LoadLibrary and GetProcAddress , which needs mangled name of the method. Does it instantiate a class object and then call the method?

如果没有,那么我该如何在类中调用方法,却实例化该类的对象然后调用方法?

If it does not then how can I call a method in a class but instantiating an object of the class and then call a method?

加载.h文件,加载类,实例化对象然后在VC ++中调用方法的过程是什么

What is process to load .h file, load class, instantiate object and then call a method in VC++

推荐答案

实际上有一个非常好

编辑(如果您已阅读上述文章),则描述了如何执行此操作的示例。

There is actually a very good example on CodeProject that describes exactly how to do this.

EDIT ,您会看到 GetProcAddress()除了返回函数指针外,无非。如果要创建从DLL导出的的实例,则必须分配内存并强制系统调用该类的构造函数在该实例中对其进行实例化。但是,一旦完成,我就假设您可以使用刚刚创建的对象以正常方式调用在类中定义的函数。

EDIT with reference to your comment, if you read the above article, you'll see that GetProcAddress() does nothing more than return a function pointer. If you want to create an instance of a class that's exported from the DLL, you have to allocate memory and force the system to invoke the constructor of the class to instantiate it there. Once that's done, however, I'm sort of assuming that you can call functions defined in the class in the normal way by using the object you just created.

这篇关于DLL加载和调用类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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