Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function with PWideChar parameter taking only first char

I've just encountered a weird problem. I am trying to load a model to OpenGL and in the part where I load textures I use auxDIBImageLoadA(dibfile:PWideChar) function. 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;    
...

The MessageBox is just for control. This is what happens: I run the application, a box with "FACE.BMP" appears. Okay. But then I get an error saying "Failed to open DIB file F". When i set the stFileName to xFACE.BMP, I get an "Failed to open DIB file x". So for some reason it appears that the function is taking only the first char.

Am I missing something? I'm using glaux.dll which I downloaded like 5 times from different sources, so it should be bug-free (I hope, every OpenGL site referred to it).

like image 332
Martin Melka Avatar asked Feb 23 '23 22:02

Martin Melka


2 Answers

That's odd, functions ending in "A" generally take PAnsiChar pointers, and those ending in "W" take PWideChar pointers. Is there a auxDIBImageLoadW call also? If there is use that one, or try with PAnsiChar, since the PWideChar you pass (two bytes per position) would look like a string one character long if it is evaluated as a 1-byte string.

like image 69
Stijn Sanders Avatar answered Feb 26 '23 12:02

Stijn Sanders


You need to convert your Unicode string to ANSI. Do it like this

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

You would be better off calling the Unicode version though

pBitmap := auxDIBImageLoadW (PWideChar(strFileName))
like image 26
David Heffernan Avatar answered Feb 26 '23 12:02

David Heffernan