Function with parameter PWideChar accepts only the first char

I just ran into some strange problem. I am trying to load a model in OpenGL, and in the part where I load textures, I use the auxDIBImageLoadA(dibfile:PWideChar) function auxDIBImageLoadA(dibfile:PWideChar) . Here is my code calling it

 procedure CreateTexture(var textureArray: array of UINT; strFileName: string; textureID: integer); // Vytvoลพenรญ textury var pBitmap: PTAUX_RGBImageRec; begin if strFileName = '' then exit; MessageBox(0,PWideChar(strFileName),nil,SW_SHOWNORMAL); pBitmap := auxDIBImageLoadA(PWideChar(strFileName)); if pBitmap = nil then exit; ... 

MessageBox is for management purposes only. Here's what happens: I run the application, a window appears with "FACE.BMP" . Good. But then I get the error message "Failed to open DIB file F" . When I set stFileName to xFACE.BMP , I get "Failed to open DIB file x" . Therefore, for some reason, it seems that the function accepts only the first char.

Am I missing something? I use glaux.dll, which I downloaded 5 times from different sources, so it should be error free (I hope every OpenGL site linked to it).

+4
source share
2 answers

Odd functions ending in "A" usually accept PAnsiChar pointers, and those ending in "W" accept PWideChar pointers. Is there a call to auxDIBImageLoadW ? If it is used, or try using PAnsiChar, since the PWideChar you pass in (two bytes per position) will look like a single character string if it is evaluated as a 1-byte string.

+7
source

You need to convert the Unicode string to ANSI. Do it like that

 pBitmap := auxDIBImageLoadA (PAnsiChar(AnsiString(strFileName))) 

You'd better name the Unicode version, though

 pBitmap := auxDIBImageLoadW (PWideChar(strFileName)) 
+1
source

All Articles