However, I didn't find a better thread for posting it.
Summary:
Several examples in the help can be improved by using constants with meaningful names, rather than using 0 for different purposes.
In several examples in the help, 0 is used pretty often with different meanings. This is didactically not good, and can even be confusing as was recently seen here on the forum. The following code illustrates the problem (It's the second example from the "Prototypes" chapter, with just comments and some blank lines removed.):
Code: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
If OpenLibrary(0, "User32.dll")
MsgBox.ProtoMessageBoxW = GetFunction(0, "MessageBoxW")
MsgBox(0, "Hello", "World")
EndIfCode: Select all
lib = OpenLibrary(#PB_Any, "User32.dll")
If libNow s/he replaces all occurences of 0 with lib and thus gets this code:
Code: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
lib = OpenLibrary(#PB_Any, "User32.dll")
If lib
MsgBox.ProtoMessageBoxW = GetFunction(lib, "MessageBoxW")
MsgBox(lib, "Hello", "World")
EndIfThis is because the 0 used with the MsgBox() function has a different meaning than the other zeros here, and must not be replaced with lib
The proper code with #PB_Any is:
Code: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
lib = OpenLibrary(#PB_Any, "User32.dll")
If lib
MsgBox.ProtoMessageBoxW = GetFunction(lib, "MessageBoxW")
MsgBox(0, "Hello", "World")
EndIfCode: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
#Library = 0
If OpenLibrary(#Library, "User32.dll")
MsgBox.ProtoMessageBoxW = GetFunction(#Library, "MessageBoxW")
MsgBox(0, "Hello", "World")
EndIfBTW, since I'm on the subject right now:
Another improvement of example codes would be, to make them ready for usage with EnableExplicit. So I actually would write the respective examle code like this:
Code: Select all
Prototype.i ProtoMessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0)
Define MsgBox.ProtoMessageBoxW
#Library = 0
If OpenLibrary(#Library, "User32.dll")
MsgBox = GetFunction(#Library, "MessageBoxW")
MsgBox(0, "Hello", "World")
EndIf


