_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("[email protected]");
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;
}
Ich nenne die obige Funktion aus einer anderen AnwendungC++ DLL-Funktionsaufruf stürzt auf Rückkehr
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 ;
}
Der Call-Stack zeigt mir dies: Symbole geladen. HEAP [MaterialCheck.exe]: Ungültige Adresse RtlValidateHeap angegeben (0000000000390000, 0000000002B82D30) und der Absturz tritt auf, wenn es sagt, dass es versucht,> mfc110ud.dll Operator (void * p) Zeile 351 C++
Kann jemand löschen! bitte hilf mir bitte. THanks
Bitte beachten Sie auch, dass es ein Tippfehler, Der Datentyp des Rückgabe eine Leere ist und kein Bool. Danke –
Definiert 'FNPTR' den richtigen Funktionszeigertyp? Verwenden Sie insbesondere die richtige Aufrufkonvention? A [mcve] würde Ihnen sowohl helfen, das Problem zu identifizieren, als auch uns helfen. – IInspectable
Die erste Sache, die ich Ihnen vorschlagen, um zu klären, ob das Problem spezifisch ist, von Dll aufzurufen oder es ist ein Problem mit der Send() - Implementierung selbst. Versuchen Sie, Send() zu exe zu verschieben und es aufzurufen. Vervielfältigt sich der Absturz? – CodeFuller