DarkBASIC Pro Tutorial: Registry Editing

James Cloud
DarkBASIC Pro Tutorial: Registry Editing
Most games and application make changes to the systems registry or to other files in order to save settings or keep logs. The various steps in this tutorial will show you how to modify the registry in your DarkBASIC Professional application or game.

Part One - Writing to the Window's Registry

In DarkBASIC Professional you can write either strings or integers to the registry using to different commands. To write a string to the system registry use the "Write String to Registry" functions. If you would like to write a number to the registry instead, use the "Write to Registry" command.

Example for writing strings to the registry:

write string to registry "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", APPNAME$, get dir$() + "\" + APPNAME$ + ".exe"

This sample will add your application to the computers start up, making it start every time the computer boots up.

Example for writing numbers to the registry:

write to registry "SOFTWARE\" + APPNAME$, "ResX", 1024
write to registry "SOFTWARE\" + APPNAME$, "ResY", 768

The code give above will write the current resolution to two keys in order for you to remember next time your game starts.

If the registry key does not exist, when you execute either of the methods above, it will be created automatically for you.

Part Two - Reading Strings and Integers from the System Registry

If you need to write to the system registry you will inevitably need to read from it as well. This is simpler then writing to the registry.

To read a string from the registry you will need to use the "get registry$" method as shown below.

Astring$ = get registry$ "SOFTWARE\" + APPNAME$ , "AString"

This code will store the specified registry key in the Astring$ string.

Reading an integer or number is quite similar. In order to read an integer from the registry simply make use the "get registry" command, like so:

Ainteger = get registry "SOFTWARE\" + APPNAME$ , "AInteger"

The above code reads an integer and stores it in the Ainteger integer.

Notice the usage of the "$" character. This character is used to distinguish when you want to use a string or not. Use "$" when you want to define or get a string.

End

Using the commands and methods given in this tutorial it will be quite easy and effective when trying to modify the Window's Registry when coding your DarkBASIC Professional game or application.

Published by James Cloud

I like to program and do basically anything that has to do with technology and computers.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.