在VC中使用MAPI,用Use Unicode Character Set选项编译出现问题。

fish_kun 2006-10-10 05:30:25
我要粘贴附件到邮件中,用了MapiFileDesc的结构,我看了一下MapiFileDesc的结构,是
typedef struct
{
ULONG ulReserved; /* Reserved for future use (must be 0) */
ULONG flFlags; /* Flags */
ULONG nPosition; /* character in text to be replaced by attachment */
LPTSTR lpszPathName; /* Full path name of attachment file */
LPTSTR lpszFileName; /* Original file name (optional) */
LPVOID lpFileType; /* Attachment file type (can be lpMapiFileTagExt) */
} MapiFileDesc, FAR * lpMapiFileDesc;
其中LPTSTR lpszPathName和LPTSTR lpszFileName都是支持unicode的(用了LPTSTR)。
但如果我粘贴一个附件,使用如下:
m_message 为一个MapiMessage变量。
m_message.lpFiles[ 0 ].lpszPathName = (LPTSTR) malloc(128);
memset(m_message.lpFiles[ 0 ].lpszPathName, 0, 128);
_tcscpy(m_message.lpFiles[0].lpszPathName, _T("D:\\HandoutReport.dat"));
m_message.lpFiles[ 0 ].lpszFileName = (LPTSTR) malloc(128);
memset(m_message.lpFiles[ 0 ].lpszFileName, 0, 128);
_tcscpy(m_message.lpFiles[0].lpszFileName, _T("HandoutReport.dat"));
不能发送成功。
如果我改为:
const char fileName[128] = "HandoutReport.dat";
const char pathName[128] = "D:\\HandoutReport.dat";
m_message.lpFiles[ 0 ].lpszPathName = (LPTSTR) malloc(128);
memset(m_message.lpFiles[ 0 ].lpszPathName, 0, 128);
strcpy( (char *) m_message.lpFiles[0].lpszPathName, pathName);
m_message.lpFiles[ 0 ].lpszFileName = (LPTSTR) malloc(128);
memset(m_message.lpFiles[ 0 ].lpszFileName, 0, 128);
strcpy( (char *) m_message.lpFiles[0].lpszFileName, fileName);
此文件被粘贴进附件了,但是我用这种方法粘两个文件进去就不成功,而在编译选项中,我如果选Use Multi-Byte Character Set而不是Use Unicode Character Set,它可以粘贴多个文件。我在Use Unicode Character Set选项下怎么才能粘贴多个文件呢?
...全文
139 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fish_kun 2006-10-11
  • 打赏
  • 举报
回复
m_message.lpFiles[ 0 ].lpszPathName = (LPTSTR) malloc(128);
memset(m_message.lpFiles[ 0 ].lpszPathName, 0, 128);
_tcscpy(m_message.lpFiles[0].lpszPathName, _T("D:\\HandoutReport.dat"));
m_message.lpFiles[ 0 ].lpszFileName = (LPTSTR) malloc(128);
memset(m_message.lpFiles[ 0 ].lpszFileName, 0, 128);
_tcscpy(m_message.lpFiles[0].lpszFileName, _T("HandoutReport.dat"));

这个方法就是用的TCHAR啊。
pomelowu 2006-10-10
  • 打赏
  • 举报
回复
都用TCHAR方式呢?
const TCHAR fileName[128] = _T("HandoutReport.dat");
const TCHAR pathName[128] = _T("D:\\HandoutReport.dat");
m_message.lpFiles[ 0 ].lpszPathName = (LPTSTR) malloc(128 * sizeof(TCHAR));
memset(m_message.lpFiles[ 0 ].lpszPathName, 0, 128 * sizeof(TCHAR));
_tcscpy( m_message.lpFiles[0].lpszPathName, pathName);
m_message.lpFiles[ 0 ].lpszFileName = (LPTSTR) malloc(128 * sizeof(TCHAR));
memset(m_message.lpFiles[ 0 ].lpszFileName, 0, 128 * sizeof(TCHAR));
_tcscpy( m_message.lpFiles[0].lpszFileName, fileName);

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧