В чем ошибка? (dll библиотека)

  • Автор темы ToRmoZzZ
  • Дата начала
T

ToRmoZzZ

Гость
#1
вот впринципе код дллки. выкидывает разные ошибки. То division By Zero, то Vector subscript out of range. Помогите! Такое ощущение что файл все таки не грузится=(

[codebox]// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright © Microsoft Corporation. All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"

#include "resource.h" // main symbols
#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
#pragma comment(lib,"Winmm.lib")

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Initialization of MFC Extension DLL

#include "afxdllx.h" // standard MFC Extension DLL routines

static AFX_EXTENSION_MODULE NEAR extensionDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
// Extension DLL one-time initialization.
if (!AfxInitExtensionModule(extensionDLL, hInstance))
return 0;

// Other initialization could be done here, as long as
// it doesn't result in direct or indirect calls to AfxGetApp.
// This extension DLL needs to add doc templates to the
// app object, so it waits for the application to boot
// and call an initialization function (see below).
}
return 1; // ok
}

// Exported DLL initialization is run in context of running application



std::vector<string> query;
std::vector<string> answer;
std::vector<string> niochem;

static string strlower(string str)
{
string s = str;
for (unsigned int i=0;i<=strlen(str.c_str());i++)
{
if ('A' <= s && s <= 'Z')
s+='a'-'A';
}
return s;
}

string deleteChars(string s)
{
string s2="";
for (int i=0;i!=strlen(s.c_str());i++)
{
if (!(s==','||s=='.'||s=='!'||s=='?'||s==':'))
s2+=s;
}
return s2;
}

string CopyStr(string s,int start,int end)
{
string st="";
for (int i=start;i<end;i++)
{
st+=s;
}
return st;
}

void explode(string in,string *out1,string *out2)
{
int n = in.find('=',1);
*out1 = CopyStr(in,0,n);
*out2 = CopyStr(in,n+1,strlen(in.c_str()));
}

__declspec (dllexport) bool loadBase()
{
char buf[255];
ifstream is("text.txt");
if (!is) return false;
query.resize(1);
answer.resize(1);
while (!is.eof())
{
is.getline(buf,255,'\n');
explode(string(buf),&query[query.size()-1],&answer[answer.size()-1]);
query.resize(query.size()+1);
answer.resize(answer.size()+1);
}
query.resize(query.size()-1);
answer.resize(answer.size()-1);
ifstream is1("niochem.txt");
niochem.resize(1);
while (!is1.eof())
{
is1.getline(buf,255,'\n');
niochem[niochem.size()-1]=buf;
niochem.resize(niochem.size()+1);
}
//niochem.resize(niochem.size()-1);
return true;
}

string noAnswer()
{
return niochem[rand()%niochem.size()];
}

__declspec (dllexport) string readForAnsw(string st)
{
std::vector<string> ans;
ans.resize(1);
for (int i=0; i<(int)query.size();i++)
{
if (query.find(st,0)!=-1)
{
ans[ans.size()-1]=answer;
ans.resize(ans.size()+1);
}
}
if (ans.size()!=1)
{
ans.resize(ans.size()-1);
return ans[rand()%ans.size()];
}
else
{
return noAnswer();
}
}
[/codebox]