首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

宏的施用不对

2013-04-09 
宏的使用不对error C2664: “MakeSureDirectoryPathExists”: 不能将参数 1 从“TCHAR [13]”转换为“PCSTR”int

宏的使用不对
error C2664: “MakeSureDirectoryPathExists”: 不能将参数 1 从“TCHAR [13]”转换为“PCSTR”







int main ()
{

#ifdef  _UNICODE
#undef  _UNICODE//我已经取消掉了,那么TCHAR则是char!!!


TCHAR strDirectory[]=_T("c:\\1111\\222\");

if (!PathFileExists(strDirectory))
{

char strTemp[MAX_PATH]={0};

//_tcsncpy(strTemp,strDirectory,lstrlen(strDirectory));

//PathRemoveBackslash(strDirectory);

//PathAddBackslash(strDirectory);

MakeSureDirectoryPathExists(strDirectory);   //error,取消掉宏了,为什么还出错?

}
#endif


return 0;

}


[解决办法]

引用:
error C2664: “MakeSureDirectoryPathExists”: 不能将参数 1 从“TCHAR [13]”转换为“PCSTR”







int main ()
{

#ifdef  _UNICODE
#undef  _UNICODE//我已经取消掉了,那么TCHAR则是char!!!


TCHAR strDirectory[]=_T("c:\\1111\\222\");

if (!PathFileExists(strDirectory))
{

char strTemp[MAX_PATH]={0};

//_tcsncpy(strTemp,strDirectory,lstrlen(strDirectory));

//PathRemoveBackslash(strDirectory);

//PathAddBackslash(strDirectory);

MakeSureDirectoryPathExists(strDirectory);   //error,取消掉宏了,为什么还出错?

}
#endif


return 0;

}
跟那个宏没有关系,与你的api参数有关
[解决办法]
引用:
引用:换成TCHAR就行了

怎么无关?

取消这个宏后,自然就是多字节了

那么 TCHAR就变成了char了。

你搞错宏的用法了,
要注意宏定义的顺序
因为TCHAR在_UNICODE定义取消前已经为宽字符了,
之后再取消_UNICODE定义不会影响之前TCHAR的定义
[解决办法]
其实都在于一个顺序问题
[解决办法]
引用:
其实都在于一个顺序问题


懂了,对于取消一个宏, 编译器只看第一次定义的时候,

不会看中途的代码的。


而对于中途修改宏的值, 这才管用
ps

热点排行