Click here to Skip to main content
15,747,766 members
Articles / Desktop Programming / Win32
Posted 19 Dec 2014


19 bookmarked

PureBasic - The Perfect Cross-Platform & Native Development Language

Rate me:
Please Sign up or sign in to vote.
4.67/5 (27 votes)
10 Jan 2015CPOL5 min read
Native, simply, fast, cross-platform, and quite powerful PL? Is it nothing? No, it isn't. It is PureBasic!

Why BASIC? Why this article?

No. I am not a BASIC adherent. I writing in more than 10 PLs including C#, Java, C++ and other main-stream PLs.

I don't think that PureBasic better than all of these PLs.

PureBasic isn't a best PL. C# is more convenient and powerful than PB for writing Windows applications. Python and Java is better for cross-platform development, not least because not compiling to platform-dependent executable format on many OSes.

But, if you want write native applications, not requiring a third-party dlls and platforms, or native and cross-platform applications, you can't use C#, Java, Python. You can use Delphi, a few C++ implementations, and a few more PLs. And, PureBasic is best for most native purposes. Really.

Also I am not a spammer advertising a commercial product on CodeProject. I do not work for the authors of PB. PB already enough popularly PL. I just help you orient that language is best for your purposes.

Why native & no 3rd-party? Why not .NET, JVM?

Where native and third-party independent development is necessary?

  1. Installers development. Installer shouldn't require a third-party platform. Also very undesirable to require a few third-party DLLs weighing a few MBs at all.
  2. SFX-archives development.
  3. CD-shells development.
  4. Drivers development. Driver just will not work if will require a .NET, JVM. high-level third-party libs.
  5. Adware and "legal adware" (with neccessary license agreement). Adware should eat a little CPU time, RAM and disk space and shouldn't require a third-party platform.
  6. Game development. There high performance needed. MS.NET or JVM are bad choice.
  7. And other soft requiring a performance and light weight.
  8. And "temporary" soft writing for experiments with undocument libx, hacks, etc. Tool for this should be quick, native and simply.

Why not Pure C/C++, Delphi, C++ Builder?

Pure C/C++ is hard to learning and using.
For example, you can't write just:
MessageBox(Str(2 + Int("2")));
intvar = Int("2");

intvar2 = 2 + intvar;

strvar = Str(intvar);

You should write:
// WARNING: compile in Unicode
#include <Windows.h>
#include <tchar.h>
#include <sstream>
#include <string>
// #pragma comment(lib, "user32.lib") --- for MessageBox, required if lib not added in the compiler options

using namespace std;

int main()
    int intvar;
    wistringstream s(_T("2"));
    s >> intvar;

    wostringstream ss;
    ss << 2 + intvar;
    wstring strvar = ss.str();

    MessageBox(0, strvar.c_str(), _T(""), MB_OK); 

    return 0;

You should learn and write a much more to obtain the same result.

Delphi and C++ Builder aren't so hard. But they are paid (and very expensive) and creating quite large EXEs. Also, Delphi has long been used as malware creating tool - now few antiviruses suspects of Delphi EXEs in malware.

PureBasic: Compiler

PB designed for Windows, Linux, Mac OS and Amiga OS development. Have x86 and x64 versions.

PB compiling to platform-dependent binary format (EXE in Win) by platform-specified compiler version.

PB compiler at first translates a PB code into FASM code and next compiles this code by FASM compiler which provides a great performance and inline FASM using possibility.

PB compiler creating a light-weight (2 KB and more), fully native EXEs requiring only msvcrt.dll and WinAPI (DependencyWalker screen):

msvcrt.dll pre-installed in Win 2000 and newer.

PureBasic: Standard Library

PB's standard library including a many of functions with different "cross-platformity" level (see documentation).

For example, it contains functions for use:

  • BMP, JPEG, JPEG2000, PNG, TGA, TIFF formats
  • Scintilla (code editing control)
  • SQLite, PostgreSQL, ODBC databases
  • Ogre 3D engine (!) It allow you to work with 2D and 3D graphics. Ogre lib integrared into PureBasic.

Also you can use a many of native OS API functions and interfaces, such as WinAPI on Windows and GDK/GTK on Linux.

PureBasic: Paradigm and Syntax

PB supports imperative and procedural paradigm. 

PB officially not fully supports object-oriented paradigm today. In PB 5.20+ (23 July 2014) you can use Modules, like a Modules in VB 6.0 / VBA or static classes in C# / VB.NET. Also you can use "dirty tricks" such as to imitate OOP in your applications.

In PB you shouldn't implement a main class or an entry point a main() in C++. You can just write a code in editor from its first to last line, such as in many of script PLs. It's very useful for "temporary" and "experimental" apps (see Why native & no 3rd-party? Why not .NET, JVM?)


Code() ; Comment as in the asm


Explicit integer variable definition:


Explicit integer variable definition and initialization:

x.i = 5

Explicit integer variable definition and using:

x = 5   

y = x * 2 ; 10

Explicit string variable definition (via 2 ways!) and using:

str1.s = "Lorem"           ; 1 way
str2$ = "ipsum"            ; 2 way

str3$ = str1 + " " + str2$ ; Lorem ipsum

Fixed string:

str1 = "Lorem ipsum" ; Lorem

str2$ = "Lorem ipsum" ; Lorem

<span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">; Other variable types see in documentation.</span>

Implicit variable definition:

x = 5
y = 2 * x ; 10

Variables convertation

Integer to string and back:

x = 5
str$ = Str(x)
x = 5 + Val(str$) ; 10

Double to string and back:

x.d = 3.2
str$ = StrD(x)
x = 2.5 + ValD(str$) ; 5.7

Double to string without 0 at end:

x.d = 3.2
str$ = StrD(x)            ; 3.2000000000
str$ = Trim(str$, "0") ; 3.2


#x = 1
#y = "2"
#z = 3.14


  #x ; 0
  #y ; 1
  #z ; 2

Ext. syntax:

Enumeration [<constant> [Step <constant>]] 
  #Constant2 [= <constant>]

Console Interface

Print("Hello world!")
Input()                      ; wait for key or input a value

Debug-time console interface

Debug "It will be printed in the debug output window"


Procedure MsgBox(text$)
  MessageRequester("", text$)

MsgBox("Hello World")

With value return:

Procedure$ InputBox(text$)
  ProcedureReturn InputRequester("", text$, "")

name$ = InputBox("Print your name")
MessageRequester("", name$)

Data in EXE

This feature resembles resources in many other programming languages. But it isn't standard Windows resources and can't be readed by hackers using ResHacker or another resource viewer.

Numerical data:

Restore NumData
Read.l A
Read.l B

MessageRequester("", Str(A))
MessageRequester("", Str(B))

  Data.l 1, 2

String data:

Restore NumData
Read$ A$
Read$ B$

MessageRequester("", A$ + B$)

  Data$ "Hello ", "world"

Text file content:

Restore File1
Read.s File1Data$

MessageRequester("", File1Data$)

  IncludeBinary "file.txt"

To be continued...

PureBasic: IDE

PureBasic IDE is very simply:

...but quite powerful:

Code regions (folding):

PureBasic: GUI

In PureBasic you can create GUI by 5 ways:

  1. Using PB's standard cross-platform GUI library only. Simplest way.
  2. Using native OS API only. For example, WinAPI allows you to create extemelly small executables, sometimes gives access to special features OS. Hardest and not always justified way.
  3. Combining PB's standard cross-platform GUI library and OS API if it needed. Prefered way in most cases.
  4. Using PB's standard cross-platform 3D GUI library. It's using 3D engine to draw game-like GUI and a bit like WPF in Microsoft .NET :) Prefered way for game and 3D graphics development.
  5. Using third-party GUI libraries based on 1, 2, 4 way or combining few ways. Backhanded way, depends on the quality of libraries.

Way 1 - Standard cross-platform GUI library

A simple GUI program in PB:

OpenWindow(#PB_Any, 10, 50, 400, 200, "Lorem ipsum", #PB_Window_SystemMenu)

ButtonGadget(#btn1, 10, 10, 100, 25, "Button 1", 0)

  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
    GadgetID = EventGadget()
    If GadgetID = #btn1
      MessageRequester("", "Button 1 clicked!")
Until Event = #PB_Event_CloseWindow
There is very simply to write GUI in the PureBasic by hand. But even quicker and possibly more convenient to use a visual (WYSIWYG) designer.
You can use a simply Visual Deigner included in PB:
... or more powerful PurePORM editor
... or create your own GUI builder :)

Way 2 - Native OS API

A simple (or not so? :)) WinAPI GUI program in PB:

; If you want to use in GUI not only latin characters, compile it in Unicode!
; Warning: exe size - it's very, very small!

Declare.l WndProc(hWnd, Msg, wParam, lParam) ; declare Window events callback

; Global vars
WindowClass.s = "WndClass1"

; Initialize Window Class
wc\cbSize = SizeOf(WNDCLASSEX)
wc\hbrBackground = #COLOR_WINDOW
wc\hCursor = LoadCursor_(0, #IDC_ARROW)
wc\lpfnWndProc = @WndProc()
wc\lpszClassName = @WindowClass

; register Window Class
If RegisterClassEx_(@wc) = 0
  MessageBox_(hWnd, "Can't register main window class.", "", #MB_ICONERROR)

; create window
hWnd = CreateWindowEx_(0, WindowClass, "Lorem ipsum", #WS_SYSMENU, 10, 50, 400, 200, 0, 0, 0, 0)
If hWnd = 0
  MessageBox_(hWnd, "Can't create main window.", "", #MB_ICONERROR)

; create button and set it's font
hButton1 = CreateWindowEx_(0, "Button", "Button 1", #WS_CHILD | #WS_VISIBLE, 10, 10, 100, 25, hWnd, 0, 0, 0) 
SendMessage_(hButton1, #WM_SETFONT, GetStockObject_(#DEFAULT_GUI_FONT), 1)

; show window
ShowWindow_(hWnd, #SW_SHOWDEFAULT) 

; messages handling loop
While GetMessage_(msg.MSG, #Null, 0, 0 ) 

; window events callback
Procedure.l WndProc(hWnd, Msg, wParam, lParam)
  Shared hButton1
  Select Msg
    Case #WM_COMMAND
      If hButton1 = lParam
        MessageBox_(hWnd, "Button 1 clicked!", "", #MB_OK)
    Case #WM_CLOSE 
    Case #WM_DESTROY 
      PostQuitMessage_(0) : Result  = 0 
      Result  = DefWindowProc_(hWnd, Msg, wParam, lParam) 
  ProcedureReturn Result 
To be continued...

PureBasic: Third-party Libraries

PureBasic open-source libraries repositary collection:
Professional GUI library:
Also you can use any other DLL by importing it functions.
To be continued... I'll add more, much more PB libs... I bit later.

PureBasic: Community and Documentation

Forums (English) (German) (French) (Russian) (Russian) (Russian) (Russian) (Chinese)

Documentation, tutorials, code samples (Russian) (Russian) (Russian) (Russian) (Russian)

Alternative PB overview article


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Comments and Discussions

Questionthanks for your introduction Pin
Southmountain10-Dec-22 7:17
Southmountain10-Dec-22 7:17 
QuestionPureBasic Pin
Member 1457158028-Aug-19 19:37
Member 1457158028-Aug-19 19:37 
QuestionPoor Emiliarge Pin
User-175147220-Nov-17 2:27
User-175147220-Nov-17 2:27 
GeneralShameless add for commercial product Pin
Jan Zumwalt20-May-15 4:31
Jan Zumwalt20-May-15 4:31 
GeneralRe: Shameless add for commercial product Pin
User-175147220-Nov-17 2:09
User-175147220-Nov-17 2:09 
GeneralMy vote of 5 Pin
blueb583-Jan-15 2:58
blueb583-Jan-15 2:58 
GeneralRe: My vote of 5 Pin
User-175147220-Nov-17 2:23
User-175147220-Nov-17 2:23 
SuggestionNice article Pin
Peter Tübben3-Jan-15 2:03
Peter Tübben3-Jan-15 2:03 
GeneralRe: Nice article Pin
Emiliarge3-Jan-15 8:41
professionalEmiliarge3-Jan-15 8:41 
GeneralRe: Nice article Pin
Emiliarge3-Jan-15 15:00
professionalEmiliarge3-Jan-15 15:00 
GeneralRe: Nice article Pin
Peter Tübben4-Jan-15 12:25
Peter Tübben4-Jan-15 12:25 
GeneralMy vote of 1 Pin
AYakovlev25-Dec-14 6:31
AYakovlev25-Dec-14 6:31 
GeneralRe: My vote of 1 Pin
Emiliarge25-Dec-14 7:04
professionalEmiliarge25-Dec-14 7:04 
GeneralRe: My vote of 1 Pin
William Atkin22-Nov-15 16:52
William Atkin22-Nov-15 16:52 
GeneralRe: My vote of 1 Pin
User-175147220-Nov-17 2:15
User-175147220-Nov-17 2:15 
GeneralRe: My vote of 1 Pin
User-175147220-Nov-17 2:24
User-175147220-Nov-17 2:24 
QuestionWhy not other versions of Basic Pin
Member 1096127724-Dec-14 3:27
Member 1096127724-Dec-14 3:27 
AnswerRe: Why not other versions of Basic Pin
Emiliarge24-Dec-14 3:55
professionalEmiliarge24-Dec-14 3:55 
GeneralRe: Why not other versions of Basic Pin
Member 1096127724-Dec-14 7:25
Member 1096127724-Dec-14 7:25 
GeneralRe: Why not other versions of Basic Pin
Emiliarge24-Dec-14 9:08
professionalEmiliarge24-Dec-14 9:08 
AnswerRe: Why not other versions of Basic Pin
User-175147220-Nov-17 2:11
User-175147220-Nov-17 2:11 
QuestionDoes it run on anything modern? Pin
Dewey23-Dec-14 13:04
Dewey23-Dec-14 13:04 
AnswerRe: Does it run on anything modern? Pin
Emiliarge23-Dec-14 16:37
professionalEmiliarge23-Dec-14 16:37 
GeneralRe: Does it run on anything modern? Pin
ISanti23-Dec-14 21:52
ISanti23-Dec-14 21:52 
GeneralRe: Does it run on anything modern? Pin
Emiliarge24-Dec-14 0:39
professionalEmiliarge24-Dec-14 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.