I have a DLL function that looks like this:
Code:
bool GetSupportedHeaders(map <string, string> &Me)
{
map <string, string> HeaderMap;
HeaderMap["Host:"] = "Hello";
Me = HeaderMap;
return true;
}
Its job is to take a <string,string> map, populate it, and give it back to the function that called it.
Now, in my main code I load and call the DLL like this:
Code:
typedef bool (*GETSUPPORTEDHEADERS) (map<string, string> &Me);
GETSUPPORTEDHEADERS GetSupportedHeaders;
HINSTANCE gSWEBS_headermapDLL;
int main()
{
map <string, string> SupportedHeaders;
gSWEBS_headermapDLL = LoadLibrary(".\\SWEBS_headermap.dll"); // Load the library
if (gSWEBS_headermapDLL == NULL)
{
cout << "Could not load DLL";
return true;
}
cout << "Library loaded succesfully" << endl;
GetSupportedHeaders = (GETSUPPORTEDHEADERS) GetProcAddress(gSWEBS_headermapDLL, "GetSupportedHeaders");
if (GetSupportedHeaders == NULL)
{
cout << "Could not find GetSupportedHeaders() :(" << endl;
return true;
}
cout << "Set GetSupportHeaders()" << endl;
GetSupportedHeaders( SupportedHeaders );
cout << "GetSupportHeaders() has returned." << endl;
cout << SupportedHeaders["Host:"];
GetSupportedHeaders = NULL;
return false;
}
Which loads the library and is supposed to print what the DLL put into the map.
When it runs I get this:
Library loaded successfully
Set GetSupportedHeaders()
GetSupportedHeaders() has returned
And then there are 2 access violations I am not too sure why, because my understanding of pointers isn't very good. Can somone please tell me whats going on and how I must fix it? Thanks