Help returning string from dll
I am trying to create a dll that returns a line from a text file given a search string. I have the code to open a file and search for the string which works fine but i can't get it to return the string.
I am a novice at c++ so a bit lost. I don't even know if i should be "throwing" a return into the middle of the code like i am. The problem code is
I get the error" cannot convert `std::string' to std::string*' in return " Any ideas?
This is what i have,
Code:
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved){
return TRUE;
}
extern "C" __declspec( dllexport ) __stdcall string* strFind(char *);
extern "C" __declspec( dllexport ) __stdcall string* strFind(char *strString)
{
char* search = strString; // search pattern
int offset;
string line;
ifstream Myfile;
Myfile.open ("example.txt");
if(Myfile.is_open())
{
while(!Myfile.eof())
{
getline(Myfile,line);
if ((offset = line.find(search, 0)) != string::npos) {
cout << "found '" << line <<endl;
return line;
}
}
Myfile.close();
}
else
cout<<"Unable to open this file."<<endl;
return 0;
}