|
Post by Nicky Peter Hollyoake on Mar 14, 2007 17:26:16 GMT -5
QUESTIONS
Q1. Is codeblocks c++? Q2. Is alot of things you do in basic4gl simaler to c++? Q3. In codeblocks does codes run like this?
Void Array[1];
Array[0] = 5; Array[1] = 3;
Is Void dim in c++? or codeblocks? or whatever the coding is (when i say c++ i'm on about codeblocks).
Q4. Does ; have to be at the end of everything on codeblocks?
Thats all.
[glow=red,2,300]Nicky[/glow]
|
|
|
Post by Supermonkey on Mar 14, 2007 17:51:06 GMT -5
No Codeblocks is an IDE for C++, however you can download it with MIngW32 which is a C++ compiler (Codeblocks = code editor - MingW32 = Compiler for C++)
Well the basic programming priciples are but the language itself is very different
Sort of just google "C++ tutorials"
^^^
Pretty much at the end of every statement, look above ^^^
|
|
|
Post by davy on Mar 14, 2007 18:38:05 GMT -5
Actually C++ REQUIRES you to assign the type to a variable.
"dim a#" is basically "float a;" "dim a" is basically "int a;" "dim a$" is basically "string a;"
See what I mean? "dim" gets replaced by the type of variable it is.
Also...
Void Array[1];
Array[0] = 5; Array[1] = 3;
Replace "Void" with a type, such as I mentioned above...
BUT... This code is bad, it could actually cause problems.
In C++, when you allocate an array, you tell it how many elements, so this would work:
int Array[2];
Array[0] = 5; Array[1] = 3;
But this would NOT!
int Array[1];
Array[0] = 5; Array[1] = 3;
It might compile, but the second one is writing outside of the array (because you allocated it with only 1 element but you are writing two elements!)
C++ does not tell you that you screwed things like that up most of the time, instead you just write to some random place in memory and you could easily crash your program.
|
|
|
Post by Nicky Peter Hollyoake on Mar 15, 2007 7:07:07 GMT -5
Oh right, thanks. Would these tutorials give me right answers for codeblocks then? cplusplus.com/doc/tutorial/I get the... int a; float a; string a; So you don't have to add '$', '#' then? what about '&' sign btw? NEVERMINDI found the answers myself to all these questions. [glow=red,2,300]Nicky[/glow]
|
|
|
Post by Nicky Peter Hollyoake on Mar 15, 2007 7:48:27 GMT -5
Ok, I picking this up really quick. But I just got a few more questions... Would someone show some example of some DLL's already created? Would you be able to write in some thngs to tell me what's happening? you know like... CLS 'Clears the screen Color(255, 0, 0) 'Sets the text color to red Know what I mean? Another thing I understand you have to put it in a code so you can put it in B4GL right? What code is that and how does it work? BTW what does void do then?
|
|
|
Post by davy on Mar 15, 2007 9:44:24 GMT -5
Glad to see you're picking C++ up, it's a really handy language. (although I've lately found myself rather drawn to C) As far as the DLL's go, download the DLL SDK ( basic4gl.net/DLL%20SDK.zip ) and look at some of those examples (they have codeblocks projects set up so all you need to do is build). The code in the SDK is commented and should help. As far as "void"... Interesting question. "void" does nothing! Well... Basically. You don't declare variables as "void", if you could it would serve no point (why use a type-less type?). But you CAN define functions as "void" and it simply means that the function doesn't return anything. Here's a stripped down Basic4GL DLL that might help you understand it a little better. I removed a lot of commenting, so be sure to explore the rest of the examples from the SDK to help you understand what it going on. It just creates a function that takes in two variables, adds them, then returns the result. "x#=add(a#, b#)" Keep in mind that I couldn't compile this to test, but I think it will work (I just modified one of the example DLL's). Just open up one of the examples from the SDK in codeblocks and change it's source to this (open up a project file, not a plain source file, because the projects are setup to compile): //kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "Basic4GLDLLInterface.h"
#include "Basic4GLStandardObjects.h"
#include <math.h>
char *pluginError = NULL;
class TestPlugin : public IDLL_Basic4GL_Plugin {
public:
TestPlugin() { ; }
virtual bool DLLFUNC Load(IDLL_Basic4GL_FunctionRegistry ®istry, bool isStandaloneExe);
virtual bool DLLFUNC Start();
virtual void DLLFUNC End();
virtual void DLLFUNC Unload();
virtual void DLLFUNC GetError(char *error);
virtual void DLLFUNC Pause();
virtual void DLLFUNC Resume();
virtual void DLLFUNC DelayedResume();
virtual void DLLFUNC ProcessMessages();
};
extern "C" {
DLLExport int DLLFUNC Basic4GL_Query(char *details, int *major, int *minor) {
char *detailSrc = "Basic4GL plugin example #1";
int i;
for (i = 0; detailSrc != 0; i++)
details = detailSrc;
*major = 1;
*minor = 0;
return BASIC4GL_DLL_VERSION;
}
DLLExport IDLL_Basic4GL_Plugin *DLLFUNC Basic4GL_Init() {
return new TestPlugin();
}
}
// Davy: LOOK HERE!!! ME ME ME!!! THIS IS THE FUNCTION!!!
void DLLFUNC Func_ADD(IDLL_Basic4GL_Runtime &basic4gl) {
// Read X parameter
float x = basic4gl.GetFloatParam(2);
// Read Y parameter
float y = basic4gl.GetFloatParam(1);
// Create result as x + y
float result = x + y;
// Return result to Basic4GL program
basic4gl.SetFloatResult(result);
}
bool DLLFUNC TestPlugin::Load(IDLL_Basic4GL_FunctionRegistry ®istry, bool isStandaloneExe) {
// Davy: This is where we register our function so that Basic4GL can use it.
registry.RegisterFunction("add", Func_ADD, DLL_BASIC4GL_FLOAT);
registry.AddParam(DLL_BASIC4GL_FLOAT);
registry.AddParam(DLL_BASIC4GL_FLOAT);
return true;
}
void DLLFUNC TestPlugin::Unload() {
delete this;
}
bool DLLFUNC TestPlugin::Start() {
return true;
}
void DLLFUNC TestPlugin::End() {}
void DLLFUNC TestPlugin::Pause() {}
void DLLFUNC TestPlugin::Resume() {}
void DLLFUNC TestPlugin::DelayedResume() {}
void DLLFUNC TestPlugin::GetError(char *error) {
if (pluginError != NULL)
for (int i = 0; pluginError != 0; i++)
error = pluginError;
}
void DLLFUNC TestPlugin::ProcessMessages() {}
|
|
|
Post by Supermonkey on Mar 15, 2007 14:08:58 GMT -5
Technically you are still giving the variable a type in basic4gl and C++ when you declare it either with the 'as' keyword or with the symbol.
|
|