Dec 4, 2016 at 8:43am UTC
Hello im trying to call a dll function from c++ builder and getting access violation.
The same code work fine in vc++ console.
can anyone check whats wrong im doing ??
DLL Code.
#include <string>
#include <vector>
#include <regex>
using namespace std;
extern "C" __declspec(dllexport)void xmlResponse(string& myString,vector<string>& vec)
{
regex rx("</data>");
vector<int> index_matches;
for (auto it = std::sregex_iterator(myString.begin(), myString.end(), rx);it != std::sregex_iterator();++it)
{
index_matches.push_back(it->position());
}
for (unsigned int i = 0; i < index_matches.size(); i++)
{
string tmp;
if (i == 0)
{
tmp = myString.substr(0, index_matches[i] + 7);
vec.push_back(tmp);
}
else
{
tmp = myString.substr(index_matches[i - 1] + 7, index_matches[i] - index_matches[i - 1]);
vec.push_back(tmp);
}
}
}
Button code in c++ builder.
typedef void (*xmlResponse)(string&, vector<string>&);
string myString =
"<?xmlversion=\"1.0\" ?><data><read SECTOR_SIZE_IN_BYTES=\"512\" num_partition_sectors=\"34\" physical_partition_number=\"0\" start_sector=\"0\"/></data><?xmlversion=\"2.0\" ?><data><read SECTOR_SIZE_IN_BYTES=\"512\" num_partition_sectors=\"34\" physical_partition_number=\"0\" start_sector=\"0\"/></data>";
HINSTANCE dllAccess = LoadLibraryA("C:\\Users\\Rahul\\Documents\\Visual Studio 2015\\Projects\\xmlRegex\\Debug\\xmlRegex.dll");
if (!dllAccess)
{
cout << "Dll Not Found" << endl;
}
xmlResponse xRes;
xRes = (xmlResponse)GetProcAddress(dllAccess, "xmlResponse");
vector<string> x;
xRes(myString, x); // getting error here.
Dec 4, 2016 at 10:21am UTC
Have you properly linked the dll from your project?