为何用A2OLE()将LPCSTR转到LPOLESTR会转换失败?

hqulyc 2005-11-12 11:46:05

char *strFile = new char[dwSize+1];
DWORD nBytesRead = 0;
BOOL bResult = ReadFile(hFile, strFile, dwSize, &nBytesRead, NULL);
if( bResult )
{
strFile[dwSize]='\0';

USES_CONVERSION;
LPOLESTR lpo = A2OLE(strFile) //这样转应该不会有错吧?
long len = wcslen( lpo ); //这里得到的长度有时正确,有时少了2
CComBSTR bstrProtoFile( dwSize, strFile );
len = bstrProtoFile.Length(); //这和上面情况一样
}
当我读取不同文件后,将lpo 的内容写入文本后,发现少了最后一个字符;可是有时候又不会少!~
请教各位大虾,哪里可能会出问题呢?

/*----------------Show Buffer-----------------------*/
FILE *fStream = fopen( strPath, "w+" );
if( fStream != NULL )
{
CString str( bstrProtoFile );
LPCSTR strText = str.GetBuffer( str.GetLength() );
UINT nWrite = fwrite( strText, sizeof(char), len, fStream );
}
fclose( fStream );
/*--------------End Of Show Buffer-------------------*/
...全文
201 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqulyc 2005-11-14
  • 打赏
  • 举报
回复
不是你说的那个问题,但分还是给你吧,没有人来了
goodboyws 2005-11-12
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/4383/4383614.xml?temp=.4298517
goodboyws 2005-11-12
  • 打赏
  • 举报
回复
LPWSTR wszImage = new WCHAR[strlen(szImage)+1];
MultiByteToWideChar(CP_ACP, 0, szImage, -1, wszImage, strlen(szImage)+1);
goodboyws 2005-11-12
  • 打赏
  • 举报
回复
字符串过长,栈空间不足

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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