将常量字符转换为 LPTSTR
我已经寻找过类似的问题,但没有一个是在我需要的上下文中。奇怪的是,我收到了这个错误,但以相同方式在代码中设置的另一个项目似乎工作得很好。
我试图将图像加载到 openGL 中的纹理中,并有一个接受此参数的函数:
GLuint loadTexture(LPTSTR szFileName);
然后我这样调用它:
textureLib[0]= loadTexture("texturelib/texture1.bmp");
textureLib[1]= loadTexture("texturelib/texture2.bmp");
textureLib[2]= loadTexture("texturelib/texture3.bmp");
textureLib[3]= loadTexture("texturelib/texture4.bmp");
然后它说“1>e:\usb\uni work\graphics\coursework\coursework\main.cpp (291):错误C2664:'loadTexture':无法将参数1从'const char [24]'转换为'LPTSTR'”
如上所述,我拥有的另一个程序似乎允许它因此,如果有一种方法可以修复它并运行它,我们将不胜感激:)
I have looked for similar problems but none are in the context I require. The odd thing with this is that I get this error yet a different project set out in code the same way seems to work perfectly.
I am trying to load images into textures in openGL and have a function which takes in this parameter:
GLuint loadTexture(LPTSTR szFileName);
I then call it like this:
textureLib[0]= loadTexture("texturelib/texture1.bmp");
textureLib[1]= loadTexture("texturelib/texture2.bmp");
textureLib[2]= loadTexture("texturelib/texture3.bmp");
textureLib[3]= loadTexture("texturelib/texture4.bmp");
it then says "1>e:\usb\uni work\graphics\coursework\coursework\main.cpp(291): error C2664: 'loadTexture' : cannot convert parameter 1 from 'const char [24]' to 'LPTSTR'"
As stated above another program that I have seems to allow it so if there is a way of just fixing it to run it that would be appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LPTSTR
是char*
或wchar_t*
,具体取决于是否设置了 Unicode 宏(UNICODE
、_UNICODE
)。如果您要向该函数传递文字,则不应使用它(而应使用 LPCTSTR,即const char/wchar_t*
)。更改签名后,使用_T()
或TEXT()
宏将文字与类型匹配,即LPTSTR
is eitherchar*
orwchar_t*
, depending on whether Unicode macros are set (UNICODE
,_UNICODE
). And if you're passing literals to that function, you should not use it (and useLPCTSTR
instead, which isconst char/wchar_t*
). After you change the signature, use_T()
orTEXT()
macro to match the literals to the type, i.e.