函数在.net2003中编辑运行没有问题,但是VC++6.0中运行出问题:
error C2664: 'lstrcpyA' : cannot convert parameter 1 from 'unsigned short *' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast还有就是在字符串前面加L或_T做用是?怎么用?(下面是我出问题的函数)
//-----------------------------------------------------------------------------
// Desc: 从绝对路径中提取件名
//-----------------------------------------------------------------------------
void RemovePathFromFileName(LPSTR fullPath, LPWSTR fileName)
{
//先将fullPath的类型变换为LPWSTR
WCHAR wszBuf[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, fullPath, -1, wszBuf, MAX_PATH );
wszBuf[MAX_PATH-1] = L'\0'; WCHAR* wszFullPath = wszBuf; //从绝对路径中提取文件名
LPWSTR pch=wcsrchr(wszFullPath,'\\');
if (pch)
lstrcpy(fileName, ++pch);
else
lstrcpy(fileName, wszFullPath);
}
error C2664: 'lstrcpyA' : cannot convert parameter 1 from 'unsigned short *' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast还有就是在字符串前面加L或_T做用是?怎么用?(下面是我出问题的函数)
//-----------------------------------------------------------------------------
// Desc: 从绝对路径中提取件名
//-----------------------------------------------------------------------------
void RemovePathFromFileName(LPSTR fullPath, LPWSTR fileName)
{
//先将fullPath的类型变换为LPWSTR
WCHAR wszBuf[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, fullPath, -1, wszBuf, MAX_PATH );
wszBuf[MAX_PATH-1] = L'\0'; WCHAR* wszFullPath = wszBuf; //从绝对路径中提取文件名
LPWSTR pch=wcsrchr(wszFullPath,'\\');
if (pch)
lstrcpy(fileName, ++pch);
else
lstrcpy(fileName, wszFullPath);
}
(char *)variables;
其实有一个函数可以实现你的功能
但我忘了
T和_TEXT一样。
写字符串常量时加上这个宏可以使你在把程序改为Unicode程序时比较容易。
和char有什么不同?
用lstrcpyW替代了lstrcpy,但又出现了个问题.LPWSTR pch=wcsrchr(wszFullPath,'\\');
这个函数,
cannot convert parameter 2 from 'const char' to 'const unsigned short *'
这个函数,
cannot convert parameter 2 from 'const char' to 'const unsigned short *'
或是
wcsrchr(wszFullPath,_T('\\'));