Error C2664: 'auxDIBImageLoadW' : cannot convert parameter 1 from 'LPSTR' to 'LPCWSTR'
重新安装Windows和VS 2012 Ultimate之后,我只是在修改代码。 该代码(如下所示)之前可以很好地工作,但是当我尝试立即运行该代码时,它出现以下错误:
1 | Error 1 error C2664: 'auxDIBImageLoadW' : cannot convert parameter 1 from 'LPSTR' to 'LPCWSTR' |
码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | void CreateTexture(GLuint textureArray[], LPSTR strFileName, int textureID) { AUX_RGBImageRec *pBitmap = NULL; if (!strFileName) // Return from the function if no file name was passed in return; pBitmap = auxDIBImageLoad(strFileName); //<-Error in this line // Load the bitmap and store the data if (pBitmap == NULL) // If we can't load the file, quit! exit(0); // Generate a texture with the associative texture ID stored in the array glGenTextures(1, &textureArray[textureID]); // This sets the alignment requirements for the start of each pixel row in memory. // glPixelStorei (GL_UNPACK_ALIGNMENT, 1); // Bind the texture to the texture arrays index and init the texture glBindTexture(GL_TEXTURE_2D, textureArray[textureID]); // Build Mipmaps (builds different versions of the picture for distances - looks better) gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); // Lastly, we need to tell OpenGL the quality of our texture map. GL_LINEAR is the smoothest. // GL_NEAREST is faster than GL_LINEAR, but looks blochy and pixelated. Good for slower computers though. // Read more about the MIN and MAG filters at the bottom of main.cpp glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // Now we need to free the bitmap data that we loaded since openGL stored it as a texture if (pBitmap) // If we loaded the bitmap { if (pBitmap->data) // If there is texture data { free(pBitmap->data); // Free the texture data, we don't need it anymore } free(pBitmap); // Free the bitmap structure } } |
我尝试了此链接,也尝试了此链接。 但仍然出现错误。
此函数在初始化后用作:
1 2 3 4 | LPCWSTR k =L"grass.bmp"; CreateTexture(g_Texture,"building1.bmp", 0); CreateTexture(g_Texture,"clock.bmp", 0); //list goes on |
你能帮我吗?
解决方案是:
更改函数原型以使用宽字符串:
1 2 3 4 5 | void CreateTexture(GLuint textureArray[], LPWSTR strFileName, int textureID) //... LPCWSTR k =L"grass.bmp"; CreateTexture(g_Texture, L"building1.bmp", 0); CreateTexture(g_Texture, L"clock.bmp", 0); |
要么
不要更改您的函数原型,而是调用API函数的
1 | pBitmap = auxDIBImageLoadA(strFileName); |
推荐:坚持使用宽弦,并使用正确的弦类型。
将" LPSTR strFileName"更改为" LPCWSTR strFileName",将" building1.bmp"更改为L" building1.bmp,将" clock.bmp"更改为L" clock.bmp"。
始终要小心,因为LPSTR是ASCII,而LPCWSTR是Unicode。 因此,如果函数需要Unicode变量(例如:L" String here"),则不能给它提供ASCII字符串。