求解了,关于LPCTSTR和LPTSTR 为什么LPTSTR GetPath();函数不能返回CString定义的变量?但是LPCTSTR GetPath();就可以?如果我没记错的话,LPCTSTR只是比LPTSTR多了一个限定词const,请教了~~~~~~~~~~~~~~~~~~~~~~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString有一个转换到LPCTSTR的运算符重载。 CString str;str.GetBuffer(0);//LPTSTR LZ的意思是:LPTSTR GetPath(){ CString ret; //代码 return ret;}这怎么行呢?返回临时对象没到LPTSTR的隐式转换。能转换意味着返回值能被修改,但返回值都析构了,怎么修改。 PXSTR GetBuffer( int nMinBufferLength ) { return( PrepareWrite( nMinBufferLength ) ); }/////////////////////////////////////////////////////////////////PXSTR PrepareWrite( int nLength ) { CStringData* pOldData = GetData(); int nShared = 1-pOldData->nRefs; // nShared < 0 means true, >= 0 means false int nTooShort = pOldData->nAllocLength-nLength; // nTooShort < 0 means true, >= 0 means false if( (nShared|nTooShort) < 0 ) // If either sign bit is set (i.e. either is less than zero), we need to copy data { PrepareWrite2( nLength ); } return( m_pszData ); }//////////////////////////////////////////////////////////////////ATL_NOINLINE void PrepareWrite2( int nLength ) { CStringData* pOldData = GetData(); if( pOldData->nDataLength > nLength ) { nLength = pOldData->nDataLength; } if( pOldData->IsShared() ) { Fork( nLength ); } else if( pOldData->nAllocLength < nLength ) { // Grow exponentially, until we hit 1K. int nNewLength = pOldData->nAllocLength; if( nNewLength > 1024 ) { nNewLength += 1024; } else { nNewLength *= 2; } if( nNewLength < nLength ) { nNewLength = nLength; } Reallocate( nNewLength ); } }知道了吧 写atl的又不是傻帽 咋会返回临时指针呢 是不是应该返回str.GetBuffer(MAX_PATH) ? 我很奇怪,为什么很多人提到 GetBuffer, 却没有人提到 GetString() ?CString str;TCHAR pbuf = str.GetString();.... 用C++操作ORACLE的例子 想找个外包 文件浏览器界面 CRichEditCtrl,CWnd,CView3者之间的问题?! 在对话框中增加CDialogBar出错了,帮帮忙。急救!!! 请帮下忙,告诉小第一下VS.NET的光盘卷标名~~` 100分寻求下载网址! 不通过键盘,不通过初始化,不用SetWindowText(),如何向一个编辑控制加字符串 问一个比较菜的问题:Hook是什么?用来做什么? 文件存取加密 Sqlite加密 想学VC,VC版本这么多,下载哪个比较好? 再求思路
str.GetBuffer(0);//LPTSTR
LPTSTR GetPath()
{
CString ret;
//代码
return ret;
}
这怎么行呢?返回临时对象没到LPTSTR的隐式转换。
能转换意味着返回值能被修改,但返回值都析构了,怎么修改。
{
return( PrepareWrite( nMinBufferLength ) );
}
/////////////////////////////////////////////////////////////////
PXSTR PrepareWrite( int nLength )
{
CStringData* pOldData = GetData();
int nShared = 1-pOldData->nRefs; // nShared < 0 means true, >= 0 means false
int nTooShort = pOldData->nAllocLength-nLength; // nTooShort < 0 means true, >= 0 means false
if( (nShared|nTooShort) < 0 ) // If either sign bit is set (i.e. either is less than zero), we need to copy data
{
PrepareWrite2( nLength );
} return( m_pszData );
}
//////////////////////////////////////////////////////////////////
ATL_NOINLINE void PrepareWrite2( int nLength )
{
CStringData* pOldData = GetData();
if( pOldData->nDataLength > nLength )
{
nLength = pOldData->nDataLength;
}
if( pOldData->IsShared() )
{
Fork( nLength );
}
else if( pOldData->nAllocLength < nLength )
{
// Grow exponentially, until we hit 1K.
int nNewLength = pOldData->nAllocLength;
if( nNewLength > 1024 )
{
nNewLength += 1024;
}
else
{
nNewLength *= 2;
}
if( nNewLength < nLength )
{
nNewLength = nLength;
}
Reallocate( nNewLength );
}
}知道了吧 写atl的又不是傻帽 咋会返回临时指针呢
是不是应该返回str.GetBuffer(MAX_PATH) ?
TCHAR pbuf = str.GetString();....