خرید بک لینک

Vote count: 0

I try to transform a Win32 Application into a DLL. But I've got some difficulties with STL vector. In original application all works fine, but in DLL "Access violation reading location" error occures. Here's the code of .h

    #ifdef NNETDLL_EXPORTS
    #define NNETDLL_API __declspec(dllexport)
    #else
    #define NNETDLL_API __declspec(dllimport)
    #endif

    #include <vector>

    using namespace std;
    #define VECARRAY vector<double>

    class NNETDLL_API CNNetDll 
    {
    public:
        CNNetDll(void);
        virtual ~CNNetDll();

        int m_InputNeurons, m_HiddenNeurons, m_OutputNeurons;

        /* Активаторы */
        vector<double> inputs;
        vector<double> hidden;
        vector<double> actual;

        /* Вход скрытых ячеек(со смещением) */
        vector<VECARRAY> who;

        /* Вход выходных ячеек(со смещением) */
        vector<VECARRAY> wih;

        int InitializeNetwork(CString FileName);
        void feedForward();
        void ActionNN(/*VECARRAY input_vec, VECARRAY& output_vec*/);
        void ReadNN(CString FileName);
    };

And here's the code of .cpp, where an exception occures

int CNNetDll::InitializeNetwork(CString FileName)
{
    int i, hid, inp, out;
    CFile f;
    CString s;
    TCHAR szDrive[200];
    TCHAR szDir[200];
    TCHAR szFile[200];
    TCHAR szExt[200];

    _wsplitpath_s(FileName, szDrive, szDir, szFile, szExt);
    SetCurrentDirectory(szDir);
    s = szExt;  FileName = szFile + s;

    f.Open(FileName, CFile::modeRead);
    f.Read(&m_InputNeurons, sizeof(double));
    f.Read(&m_HiddenNeurons, sizeof(double));
    f.Read(&m_OutputNeurons, sizeof(double));

    for (i = 0; i < m_InputNeurons; i++)
    {
        inputs.push_back(0.0); // !!!!! ERROR IS HERE !!!!!!
    }
    for (i = 0; i < m_HiddenNeurons; i++)
    {
        hidden.push_back(0.0);
    }
    for (i = 0; i < m_OutputNeurons; i++)
    {
        actual.push_back(0.0);
    }
    for (i = 0; i < m_HiddenNeurons + 1; i++)
    {
        who.push_back(actual);
    }
    for (i = 0; i < m_InputNeurons + 1; i++)
    {
        wih.push_back(hidden);
    }
    for (hid = 0; hid < m_HiddenNeurons; hid++)
    {
        for (inp = 0; inp <= m_InputNeurons; inp++)
        {
            f.Read(&wih[inp][hid], sizeof(double));
        }
    }
    for (out = 0; out < m_OutputNeurons; out++)
    {
        for (hid = 0; hid <= m_HiddenNeurons; hid++)
        {
            f.Read(&who[hid][out], sizeof(double));
        }
    }

    f.Close();

    retu 1;
}

The app falls trying to fill the vector. The last step in callstack is in "xutility" file on this lines:

inline void _Container_base12::_Orphan_all()
    {   // orphan all iterators
 #if _ITERATOR_DEBUG_LEVEL == 2
    if (_Myproxy != 0)
        {   // proxy allocated, drain it
        _Lockit _Lock(_LOCK_DEBUG);

        for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
            *_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter) // !!!!LAST OPERATION BEFORE EXCEPTION!!!
            (*_Pnext)->_Myproxy = 0;
        _Myproxy->_Myfirstiter = 0;
        }
 #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
    }

Repeating, in original application everithing works fine. Also I notice, that the error arises with that vector, which declaration goes first in CNNetDll class. In above code it's vector "inputs". If I change declarations like this

vector<double> hidden;
vector<double> actual;
vector<double> inputs;

then the exception arises with vector "hidden" on this code

for (i = 0; i < m_InputNeurons; i++)
{
    inputs.push_back(0.0); //!!!! works properly !!!!!
}
for (i = 0; i < m_HiddenNeurons; i++)
{
    hidden.push_back(0.0); // !!! exception here !!!
}
for (i = 0; i < m_OutputNeurons; i++)
{
    actual.push_back(0.0);
}

Оbject creation and function call:

CNNetDll ;
.InitializeNetwork(_T("M:\Tasks\2016\Win8-64\AI\NNet\Debug\NN.dat"));

How to solve this problem????

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 21 ارديبهشت 1395 ساعت: 16:03

صفحه بندی