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?Code:return line;
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; }



LinkBack URL
About LinkBacks




), just copy it over to char* buffer after all is done.
By the time you get the pointer back, the string object is destroyed. Even though the memory is probably unchanged at the moment and it may look like no big deal, it can be claimed and changed any moment now.