purebasic icon indicating copy to clipboard operation
purebasic copied to clipboard

PB Help: Broken Prototype Example

Open tajmone opened this issue 3 years ago • 1 comments

The following code example from the Prototypes section of the PB Help (Windows) doesn't seem to work as expected (the text and title in the resulting message box are broken):

  Prototype.i ProtoMessageBox(Window.i, Body$, Title$, Flags.i = 0)

  If OpenLibrary(0, "User32.dll")
   
    ; 'MsgBox' is a variable with a 'ProtoMessageBox' type
    ;
    MsgBox.ProtoMessageBox = GetFunction(0, "MessageBoxA")
    
    MsgBox(0, "Hello", "World") ; We don't specify the flags
  EndIf

Tested under Win 10 x64, using PB 5.73.

If you change line 7 to:

MsgBox.ProtoMessageBox = GetFunction(0, "MessageBoxW")

It works as expected. So it looks like it's just old code relying on ASCII interfaces, from the pre-Unicode PB era.

Also, it would make more sense to change line 9 to:

MsgBox(0, "World", "Hello") ; We don't specify the flags

since the title and body text are in inverted order in the final window.

tajmone avatar Jan 28 '21 04:01 tajmone

You are right, should be changed.

fantaisie-software avatar Jan 28 '21 10:01 fantaisie-software