LPCWSTR转换为LPCSTR的问题

zhujunlongzhiyan 2011-03-26 10:51:23
hHeightBmp = (HBITMAP)::LoadImage( NULL,szHeightMapPath, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE );

D3DXCreateTextureFromFile( m_pDevice, szMainTexPath, &m_pMainTex );

ERROR:“LoadImageA”: 不能将参数 2 从“LPCWSTR”转换为“LPCSTR”
“D3DXCreateTextureFromFileA”: 不能将参数 2 从“LPCWSTR”转换为“LPCSTR”

应该如何改正,菜鸟敬上~

...全文
1353 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujunlongzhiyan 2011-03-26
  • 打赏
  • 举报
回复
恩 懂了 谢谢了
Lactoferrin 2011-03-26
  • 打赏
  • 举报
回复
用接受宽字符的api版本
如果没有宏UNICODE,则LoadImage被定义成LoadImageA,这是接受ANSI字符的
zhujunlongzhiyan 2011-03-26
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lactoferrin 的回复:]
hHeightBmp = (HBITMAP)::LoadImageW( NULL,szHeightMapPath, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE );

D3DXCreateTextureFromFileW( m_pDevice, szMainTexPath, &m_pMainTex );
[/Quote]

可以运行了 谢谢了
虚心求教下:LoadImageW加个'w'是什么作用
Lactoferrin 2011-03-26
  • 打赏
  • 举报
回复
hHeightBmp = (HBITMAP)::LoadImageW( NULL,szHeightMapPath, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE );

D3DXCreateTextureFromFileW( m_pDevice, szMainTexPath, &m_pMainTex );
zhujunlongzhiyan 2011-03-26
  • 打赏
  • 举报
回复
(LPCWSTR)szHeightMapPath这样还是会提示error
不过改成(LPCWSTR)szHeightMapPath可以运行
但提示 0x00414078 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突
继续求教~~~
delphiwcdj 2011-03-26
  • 打赏
  • 举报
回复
这个用起来确实麻烦
yiyefangzhou24 2011-03-26
  • 打赏
  • 举报
回复
CString 转char *

CString cstr;

char *p = (LPSTR)(LPCTSTR)cstr;

string 转 CString
CString.format(”%s”, string.c_str());

char 转 CString
CString.format(”%s”, char*);

char 转 string
string s(char *);

string 转 char *
char *p = string.c_str();

CString 转 string
string s(CString.GetBuffer());
CString 转char *

CString cstr;

char *p = (LPSTR)(LPCTSTR)cstr;

string 转 CString
CString.format(”%s”, string.c_str());

char 转 CString
CString.format(”%s”, char*);

char 转 string
string s(char *);

string 转 char *
char *p = string.c_str();

CString 转 string
string s(CString.GetBuffer());
xali 2011-03-26
  • 打赏
  • 举报
回复
可以试一下(LPCWSTR)szHeightMapPath
CppCoder 2011-03-26
  • 打赏
  • 举报
回复
MultiByteToWideChar
zhujunlongzhiyan 2011-03-26
  • 打赏
  • 举报
回复
这个帖子看过 没看懂 具体如何改正还是不得而知呀
maoxing63570 2011-03-26
  • 打赏
  • 举报
回复
wince上各种类型转换特别是字符串是很头疼的,这个类是项目用的, 每个都测试好用,使用静态方法,直接引用后,写【::cv::就可以用】 typedef int u32; //转换类,所有的转换函数在这里静态 2是to的意思 //cs:cstring //s:string //i:int class cv { public: static char * s2charx(string s); //static char * cs2charx_unicode(CString s); static char * cs2charx_unicode(CString s); static CString charx2cs(char *s); cv(); virtual ~cv(); static int cstring_to_int(CString t); static CString s2cs(string text); static CString i2cs(int i); static string cs2s(CString s); static void Utf8ToUnicode(wchar_t* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static void Gb2312ToUnicode(wchar_t* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static CString string_to_cstring(string text); static int string_to_int(string str); static string cstring_to_string(CString text); static void Gb2312ToUtf8(char* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static BOOL IsNumeric(string text); static void UnicodeToGb2312(char* pstrOut, u32 dwOutLen, const wchar_t* pstrIn, u32 dwInLen); static void Utf8ToGb2312(char* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static int cs2i(CString s); static string int_to_string(int n); static CString ChineseCapitalMoney(double Num); //static wstring s2ws( string s ); static std::wstring s2ws(const string& s); static std::string WChar2Ansi(LPCWSTR pwszSrc); static string ws2s(wstring& inputws); static const char * s2constcharx(string s); static std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen); static char * cs2charx_ansi(CString s); //static string ws2s(wstring ws); };

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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