_declspec(dllexport) void Send(string strEmailAddress, string strHostAddress, string strUserName, string strPswrd, string strLocalFile, string strServerLocation, string strErrorMessage )
{
nsFTP::CFTPClient ft ;
wstring wstrHostName ( strHostAddress.begin(),strHostAddress.end() );
string strApplicationUserName = "acpmat";
string strApplicationPswrd = "A1c2p.M3a4t";
wstring wstrUserName ( strApplicationUserName.begin(),strApplicationUserName.end() );
wstring wstrPwrd ( strApplicationPswrd.begin(),strApplicationPswrd.end() );
wstring wstrLocalFile( strLocalFile.begin(),strLocalFile.end() );
wstring wstrServerLoc( strServerLocation.begin(),strServerLocation.end() );
nsFTP::CLogonInfo logonInfo(wstrHostName, 21, wstrUserName, wstrPwrd);
// connect to server
ft.Login(logonInfo);
ft.UploadFile(wstrLocalFile, wstrServerLoc);
CArray<CString, LPCTSTR> xToEmails;
wstring strMailTo( strEmailAddress.begin(), strEmailAddress.end() );
xToEmails.Add(strMailTo.c_str());
const CString xCCEmail;
const CString xReplyTo;
const CString xSubject(strErrorMessage.c_str());
strUserName.append( " " );
strUserName.append( strLocalFile.c_str() );
const CString xBodyFilePath( strUserName.c_str() );
const CString& xFrom = _T("Exe_Crash@cat.com");
const CString& xAttachmentFilePath = _T("");
const CString& xServer = PES_EMAIL_SERVER;
int xPort = PES_EMAIL_PORT;
const CString& xCommand = PES_EMAIL_COMMAND;
int lRes = email::Send(xToEmails, xCCEmail, xReplyTo, xSubject, xBodyFilePath);
return true;
}
I call the above function from another application
typedef void (*FNPTR)(string a, string b, string c, string d, string e, string f, string g );
//typedef int (__cdecl *MYPROC)(LPWSTR);
HINSTANCE hinstLib;
//MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess;
hinstLib = LoadLibrary(TEXT("DllCrashReport.dll"));
if (hinstLib != NULL)
{
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
FNPTR fn = (FNPTR)GetProcAddress(hinstLib, "Send");
// If the function address is valid, call the function.
if (NULL != fn)
{
TCHAR name_1 [ UNLEN + 1 ];
DWORD size_1 = UNLEN + 1;
GetUserName( (TCHAR*)name_1, &size_1 );
strUserName.clear();
strUserName.append( name_1 );
//use converter (.to_bytes: wstr->str, .from_bytes: str->wstr)
std::string converted_str( strUserName.begin() , strUserName.end() );
fRunTimeLinkSuccess = TRUE;
fn( strEmailAddress, strHostAddress, converted_str, strPswrd, strLocalFile, strServerLocation, strMailErrorMessage );
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function
if (!fRunTimeLinkSuccess)
return ;
}
The call stack shows me this: Symbols loaded. HEAP[MaterialCheck.exe]: Invalid address specified to RtlValidateHeap( 0000000000390000, 0000000002B82D30 ) and the crash occurs when it says that it tries to > mfc110ud.dll!operator delete(void * p) Line 351 C++
Can someone kindly help me please. THanks