在c ++中调用私有函数 [英] call Private function in c++

查看:278
本文介绍了在c ++中调用私有函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在C ++中调用私有方法





我有一个DLL,在那个DLL中,它们暴露了一些函数,但其​​中一个是私有的。函数 C_MORPHO_Device :: InitUsbDevicesNameEnum(PUL o_pul_NbUsbDevice)

如何调用

How can I call this InitUsbDevicesNameEnum function in my application?

推荐答案

私有方法是否也被导出?我怀疑(为什么他们会导出私有方法?)。但是如果导出,可以使用 dumpbin / exports 命令查看装饰的方法名称,然后使用GetProcAddress获取方法的函数指针并调用该类的实例。像:

Is the private method also exported? I doubt it (why would they export a private method?). But if it is exported, you can use the dumpbin /exports command to see the decorated method name, then use GetProcAddress to get a function pointer to the method and call on an instance of the class. Something like:

HMODULE hModule = LoadLibrary(L"thedll.dll");
(C_MORPHO_Device::*pMethod)(PUL) = reinterpret_cast<(C_MORPHO_Device::*)(PUL)>(GetProcAddress(hModule, L"InitUsbDevicesNameEnum@_ABunchOfSymbolsHere"));

C_MORPHO_Device device;
(device.*pMethod)(...);

这篇关于在c ++中调用私有函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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