The value of ESP was not properly saved across a f

2019-08-27 20:43发布

I made a .dll file with QT and I load it in my application. When it's about to return from one function, I receive:

The value of ESP was not properly saved across a function call

I start with the DLL project:

This is my 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__

This my 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__

This is my 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 is function containing in xfsapi.h and defined like this.

HRESULT extern WINAPI WFSStartUp ( DWORD dwVersionsRequired, LPWFSVERSION lpWFSVersion);

This is my 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__

This is my 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);

This project provides a DLL file called WINCORE.dll.

This is how I load this .dll:

QPluginLoader* pluginLoader = new QPluginLoader(filename);

QObject *plugin = pluginLoader->instance();

The filename contains the WINCORE.dll path and it's correct. My problem is startup() in the DeviceManager class. When it wants to return version, I get the error. What am I doing wrong?

1条回答
干净又极端
2楼-- · 2019-08-27 20:57

I finally found how to fix this problem!

Right click on your Project , Choose Properties , Go to Configuration Properties , Select C/C++ then select Code Generation .

Change Basic Run Time Check to Default.

Change Struct Member Alliance to 1 Byte (/Zp1) .

I really hope this work for you guys too.

Best Regards

查看更多
登录 后发表回答