未处理的异常:_com_error内存位置 0x0040f4ac
Unhandled exception : _com_error at memory location 0x0040f4ac
我正在使用外部库EASendMail使用gmail作为SMTP服务器发送电子邮件。
导致错误的行
oSmtp->许可证代码 = _T("TryIt");
用于安装外部库的链接。
#include "stdafx.h"
#include <iostream>
#include "easendmailobj.tlh"
#include <string>
using namespace EASendMailObjLib;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string Lrecipient_email = "foobar@hotmail.com";
::CoInitialize( NULL );
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
oSmtp->LicenseCode = _T("TryIt"); //error is here
// Set your gmail email address
oSmtp->FromAddr = _T(" mygmailacc@gmail.com");
// Add recipient email address
oSmtp->AddRecipientEx( _T(recipient_email.c_str()), 0);
// Set email subject
oSmtp->Subject = _T("Payment of Desposit Required");
// Set email body
oSmtp->BodyText = _T("Dear Customer , Please pay your deposit now !!!");
// Gmail SMTP server address
oSmtp->ServerAddr = _T("smtp.gmail.com");
// If you want to use direct SSL 465 port,
// Please add this line, otherwise TLS will be used.
// oSmtp->ServerPort = 465;
// detect SSL/TLS automatically
oSmtp->SSL_init();
// Gmail user authentication should use your
// Gmail email address as the user name.
// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
oSmtp->UserName = _T("username");
oSmtp->Password = _T("password");
_tprintf(_T("Start to send email via gmail account ...rn" ));
if( oSmtp->SendMail() == 0 )
{
_tprintf( _T("email was sent successfully!rn"));
}
else
{
_tprintf( _T("failed to send email with the following error: %srn"),
(const TCHAR*)oSmtp->GetLastErrDescription());
}
if( oSmtp != NULL )
oSmtp.Release();
return 0;
}
我不知道为什么我会收到以下错误:
Unhandled exception at 0x7558c41f in SendEmail.exe: Microsoft C++ exception: _com_error at memory location 0x0040f4ac..
MS Studio调试器将此显示为文件中的错误源:easendmailobj.tli
错误 1
Interface* operator->() const
{
if (m_pInterface == NULL)
{
_com_issue_error(E_POINTER);
}
return m_pInterface;
}
错误 2
inline void IMail::PutLicenseCode ( _bstr_t pVal ) {
HRESULT _hr = put_LicenseCode(pVal);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
}
oSmtp->LicenseCode = _T("TryIt");当您的试用版到期时,会发生此错误。
"TryIt"是评估许可证代码,只能用于演示目的。许可证到期 1 个月后,它会引发 COM 异常。
您可以进一步查看这些链接
https://www.emailarchitect.net/easendmail/sdk/html/LicenseCode.htmhttps://www.emailarchitect.net/easendmail/sdk/html/license.htm
最好的办法是用
try{
....
}catch(_com_error& ex){
e=e;//a break point here
}
并使用调试器单步执行代码。一旦它进入捕获部分,它就是先前调用的方法导致了它。通常对于这个 COM 的东西(我不喜欢它,但对它有些熟悉)它发生是因为早期的方法获得了错误的参数,所以它返回了一个空指针或类似的东西。
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance( "EASendMailObj.Mail");
这可能是问题所在。首先,您将 NULL 分配给 oSmtp
,而不是尝试访问它。请验证,oSmtp
可能为空。
相关文章:
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 如何在不等待检索的情况下获取C++中的内存位置?
- 向量的内存位置不连续
- 如何根据C++在同一内存位置重新初始化 C# 中的对象(还是自动完成)?
- 常量引用的内存位置
- C++强制变量到一个固定的内存位置
- 为什么未初始化的内存位置的值给出 -842150451 的值?
- 为什么存储在内存位置的值会发生变化?
- 在特定内存位置构造 c++ 对象
- 如果不初始化结构中的向量,它会自动为空还是具有随机内存位置的值?
- 内存位置出现Microsoft C++异常:std::out_of_range
- 函数,返回变量c++占用的内存位置的大小
- 无法在 Opencv 中显示图像导致内存位置
- 从十六进制到双的转换始终导致内存位置的 std::out_of_range
- 错误 在测试.exe 0x76C9FD62时出现未经处理的异常:Microsoft C++异常:内存位置0x006FF8
- 错误:内存位置的 std::length_error
- C++不同内存位置中的默认数组值
- 为什么动态分配的两个变量的内存位置不是连续的?
- Boost.进程间内存位置
- 查找编译时构造类的内存位置