zhucde (虚拟闲人) 的博客

OGRE,FLY3D, 图形开发, 一起探讨吧.QQ超级群(500人):186898914 QQ群(200人):23806843
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Ogre中解决中文路径和中文文件名的方法

Posted on 2011-03-11 00:04  zhucde  阅读(802)  评论(2编辑  收藏  举报

平时嫌麻烦, 一般采用setlocale(LC_ALL,"Chinese-simplified"); 的方法, 基本也能解决问题, 虽然很多人说这个方法不好 , 懒的管了.

可当把程序设置为" 在静态库中使用MFC"时, 这个方法就不灵了, 如该链接中:http://blog.csdn.net/pizi0475/archive/2010/03/01/5335677.aspx,  提到的方法都不能解决问题.

网上查了多种方法, 测试发现这种方法是有效的:

WCHAR * MtoW(const char* str)
	{
		WCHAR*     strA;       
		int i= MultiByteToWideChar(CP_ACP,0 ,(char*)str,-1,NULL,0);  

		strA = new WCHAR[i];       
		MultiByteToWideChar(CP_ACP,0,(char*)str,-1,strA,i);      

		return strA;
	}

在OgreFileSystem.cpp的

DataStreamPtr FileSystemArchive::open(const String& filename) const 函数中:

origStream->open(MtoW(full_path.c_str()), std::ios::in | std::ios::binary);  //使用MtoW转换一下

Everything is all righit.