Hi guys, I searched and found afew posts on using strings with the gdk, and while I have tried those solutions I still can't get them to work, mostly because i'm very new to c/c++.
#include "DarkGDK.h" //<-- this is the DarkBasic GDK
// My own include files
#include "main.h"
#include <string> // <-- need this to use string variables????
struct object
{
int pos_x;
int pos_y;
int pos_z;
int rot_x;
int rot_y;
int rot_z;
int scale_x;
int scale_y;
int scale_z;
std::string name;
int number;
};
void DarkGDK(void)
{
// set up initial text settings
dbSetTextFont("arial");
dbSetTextSize(12);
bool dev_mode_1=true; //<-- dev temp variable
dbSync();
dbPrint("main.cpp - Loading settings...");
load_settings();
while (LoopGDK())
{
// update screen
dbSync();
}
}
void load_settings(void)
{
object a;
a.name("hello this is what seems to be a string");
dbPrint(const_cast<char*>(a.name.c_str()));
}
I cut and pasted the parts in question from my program. I've prototyped the load_settings function in the main.h file.. everything works ok if i comment out all the string stuff. I've tried different combinations of getting the string to work but yeah, i'm new. I do have a book i borrowed from the library plus I ordered two stephen prata ones from amazon (waiting to be delivered).
Also, while i'm making a post I may aswell ask some other questions.. I'm trying to get the following code from dbp to work with the gdk;
rem file reading/writing functions
rem must be used with call dll
function InitialiseKernel32DLL()
load dll "kernel32.dll",100
endfunction
function ShutdownKernel32DLL()
delete dll 100
endfunction
function INI_ReadInteger(FileName as string, Section as string, KeyName as string, Default as integer)
r as integer
r=val(INI_ReadString(FileName, Section, KeyName, str$(Default)))
endfunction r
function INI_WriteInteger(FileName as string, Section as string, KeyName as string, Value as integer)
INI_WriteString(FileName, Section, KeyName, str$(Value))
endfunction
function INI_ReadString(FileName as string, Section as string, KeyName as string, Default as string)
r as string
r=space$(1024)
FileName = get dir$() + "\" + FileName ` + ".ini"
call dll 100, "GetPrivateProfileStringA", Section, KeyName, Default, r, len(r), FileName
endfunction r
function INI_WriteString(FileName as string, Section as string, KeyName as string, Value as string)
FileName = get dir$() + "\" + FileName ` + ".ini"
call dll 100, "WritePrivateProfileStringA", Section, KeyName, Value, FileName
endfunction
I tried rewriting it to what i thought it would be;
// file reading/writing functions
// must be used with call dll
void InitialiseKernel32DLL(void)
{
dbLoadDLL((DWORD)"kernel32.dll",100);
}
void ShutdownKernel32DLL(void)
{
dbDeleteDLL(100);
}
char* INI_ReadString(char* FileName,char* Section,char* KeyName,char* Default)
{
char* r;
r=dbSpace(1024);
FileName = dbGetDir() + "\" + FileName ` + ".ini";
dbCallDLL(100,"GetPrivateProfileStringA", Section, KeyName, Default, r, dbLen(r), FileName);
return r;
}
int INI_ReadInteger(char* FileName,char* Section,char* KeyName,int Default)
{
int r;
r=dbVal(INI_ReadString(FileName, Section, KeyName,dbStr(Default)));
return r;
}
void INI_WriteInteger(char* FileName,char* Section,char* KeyName,int Value)
{
INI_WriteString(FileName, Section, KeyName,dbStr(Value));
}
void INI_WriteString(char* FileName,char* Section,char* KeyName,char* Value)
{
FileName = dbGetDir() + "\" + FileName ` + ".ini";
dbCallDLL(100,"WritePrivateProfileStringA", Section, KeyName, Value, FileName);
}
I prototyped the functions in the main.h file.. I can get the first two functions to work, but after that I get too many errors to know what I'm doing lol. I block comment out most of the functions and try to solve one at a time. I know someone will probaly read this and say "why not use cout,cin and do your file reading writing functions that way".. well I thought it would be easier to change an already existing function to work with the gdk than write one from scratch.. and I like the way the text file comes out when using these functions..
[Program Window]
window_title=BattleTech v0.1b
window_maximize=0
[Display]
resolution_width=1024
resolution_height=768
resolution_depth=32
sync_rate=0
camera_range_near=1
camera_range_far=20000
[General]
show_mouse=0
auto_camera=0
debug=1
backdrop=1
[Game]
ambient_light=75
fog_on=1
fog_red=200
fog_green=200
fog_blue=200
fog_distance_near=10000
fog_distance_far=20000
fog_fov=35
fog_effect=0
elevation_view=10
Could someone maybe rewrite one as an example (preferable) or point me in the right direction please.