我用 QT 制作了一个 .dll 文件并将其加载到我的应用程序中。当它即将从一个函数返回时,我收到:
The value of ESP was not properly saved across a function call
我从 DLL 项目开始:
这是我的 device_manager_interface.hpp:
#ifndef __DEVICE_MANAGER_INTERFACE_HPP__
#define __DEVICE_MANAGER_INTERFACE_HPP__
#include <QtCore>
class DeviceManagerInterface
{
public:
virtual BCR * getDeviceBCR() = 0 ;
.
.
.
};
QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(DeviceManagerInterface,"some_info");
QT_END_NAMESPACE
#endif //__DEVICE_MANAGER_INTERFACE_HPP__
这是我的 device_manager.hpp:
#ifndef __DEVICE_MANAGER_BASE_HPP__
#define __DEVICE_MANAGER_BASE_HPP__
#include "device_manager_interface.hpp"
class DeviceManager : public DeviceManagerInterface
{
public:
DeviceManager();
virtual BCR * getDeviceBCR();
.
.
.
protected:
virtual void initilzeAvailableDevices(DeviceList device_list);
virtual WORD startup();
.
.
.
};
#endif //__DEVICE_MANAGER_BASE_HPP__
这是我的 device_manager.cpp:
#include "device_manager.hpp"
DeviceManager::DeviceManager()
{
}
void WINAPI DeviceManager::initilzeAvailableDevices(DeviceList device_list)
{
WORD wfs_version = startup();
.
.
.
}
WORD DeviceManager::startup()
{
WFSVERSION wfs_version;
HRESULT hRes;
hRes = WFSStartUp(SUPPORTED_VERSIONS, &wfs_version);
WORD version = wfs_version.wVersion;
return version;
}
WFSStartUp 是包含在xfsapi.h
中的函数,定义如下。
HRESULT extern WINAPI WFSStartUp ( DWORD dwVersionsRequired, LPWFSVERSION lpWFSVersion);
这是我的 device_manager_impl.hpp:
#ifndef __DEVICE_MANAGER_WINCORE_HPP__
#define __DEVICE_MANAGER_WINCORE_HPP__
#include "device_manager.hpp"
class DeviceManagerImpl : public QObject, DeviceManager
{
Q_OBJECT
Q_INTERFACES(DeviceManagerInterface)
public:
DeviceManagerImpl();
protected:
.
.
.
};
#endif //__DEVICE_MANAGER_WINCORE_HPP__
这是我的 device_manager_impl.cpp:
#include "device_manager_impl.hpp"
#include "xfsapi.h"
#define BRAND_NAME "WINCORE"
DeviceManagerImpl::DeviceManagerImpl()
{
m_brand_name = BRAND_NAME;
fill_map_logical_names();
DeviceList device_list = detectAvailableDevices();
DeviceManager::initilzeAvailableDevices(device_list);
}
Q_EXPORT_PLUGIN2(device_manager_impl, DeviceManagerImpl);
该项目提供了一个名为 WINCORE.dll 的 DLL 文件。
这是我加载此 .dll 的方式:
QPluginLoader* pluginLoader = new QPluginLoader(filename);
QObject *plugin = pluginLoader->instance();
filename
包含 WINCORE.dll 路径并且是正确的。我的问题是 DeviceManager
类中的 startup()
。当它想要返回 version
时,我得到了错误。我做错了什么?
最佳答案
我终于找到了解决这个问题的方法!
右键单击您的项目,选择属性,转到配置属性,然后选择C/C++选择代码生成。
将基本运行时检查更改为默认
。
将 Struct Member Alliance 更改为 1 Byte (/Zp1)
。
我真的希望这对你们也有用。
最好的问候
关于c++ - ESP 的值未在函数调用错误中正确保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18614054/