Pseudotypes
DescriptionFor advanced programmers. The pseudotypes are a way to ease the programming when dealing with external libraries which need datatypes that are not internally supported by PureBasic. In this case, it is possible to use the predefined pseudotype which will do the appropriate conversion on the fly, without extra work. As they are not 'real' types, the chosen naming scheme is explicitly different: a 'p-' prefix (for 'pseudo') is part of the type name. The available pseudotypes are:p-ascii: acts as a string type, but will always convert the string to ascii before calling the function, even when the program is compiled in unicode mode. It is very useful when accessing a shared library which doesn't have unicode support in an unicode program for example. p-utf8: acts as a string type, but will always convert the string to utf8 before calling the function. It is very useful when accessing a shared library which needs its unicode string be passed as UTF8 instead of ascii or unicode strings. p-bstr: acts as a string type, but will always convert the string to bstr before calling the function. It is very useful when accessing a shared library which needs bstr parameters, like COM components. p-unicode: acts as a string type, but will always convert the string to unicode before calling the function, even when the program is compiled in ascii mode. It is very useful when accessing a shared library which only supports unicode in an ascii program for example. p-variant: acts as a numeric type, will adjust the function call to use the variant parameter correctly. It is very useful when accessing a shared library which needs 'variant' parameters, like COM components.The pseudotypes can only be used with prototypes, interfaces and imported functions. The pseudotypes does the appropriate conversion only if it is necessary.
Example
Import "User32.lib" ; We use the 'p-unicode' pseudotype for the string parameters, as ; MessageBoxW() is an unicode only function. The compiler will ; automatically converts the strings to unicode when needed. ; MessageBoxW(Window.i, Body.p-unicode, Title.p-unicode, Flags.i = 0) EndImport ; It will work correctly in ascii and in unicode mode, even if the API is unicode ; only as the compiler will take care of the conversion itself. ; MessageBoxW(0, "Hello", "World")