April 24, 2024, 10:49:21 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


DLL's 101 (Based on Zens example)

Started by J B Wood (Zumwalt), October 23, 2006, 05:14:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

Zen went into this briefly for Kryton, but I thought I would slightly expand on it since I am looking at writing some dll wrappers that are exposed.
Taking the basics of Zens code:

Step 1 Create your Source file, place this code in it:

/*** The Export Keyword Tells The Linker ***/
/*** That The Specified Subroutines AreÂÃ,  ***/
/***ÂÃ,  ÂÃ, To Be Made Visible So To SpeakÂÃ,  ÂÃ,  ***/
/*******************************************/

export myFirstFunction;
export myCalcFunction;

/*************************************/
/*** Simple Hello World Subroutine ***/
/*************************************/

sub myFirstFunction(),string {

return "Hello World!";

}

/***************************************/
/*** Simple Math Addition Subroutine ***/
/***************************************/

sub myCalcFunction(float val1, float val2),float {

return val1 + val2;

}


Name the source myFirst.src, then save it.
Now compile as a single build type DLL (not worring about a project yet)
You will now have a DLL named myFirst.dll

Step 2:
In Aurora, click on Tools, Create Import Library
Browse out to your folder where your myFirst.dll is stored, and choose it and click Open.
This will create a myFirst.Lib file in your Aurora/Libs folder for your DLL.

Step 3:
Create a new source placing the following code into it:

/* This shows how to use myFirst.dll */
#use "myFirst.lib"
declare extern myFirstFunction(),string;
declare extern myCalcFunction(float val1, float val2),float;

global sub main()
{
int test=MessageBox(NULL,myFirstFunction(),"Hello World Call");
test=MessageBox(NULL,STR$(myCalcFunction(1,2)),"Calculate!");
}


NOTE: typically you put declares in include files, that is covered later, for now just use a single source without an include.
Save this new source fileÂÃ,  and name it useFirst.src and compile.
Now, when you run it, you will get 2 message boxes, the first will say "Hello World!", the second will have a 3 in it.

As you can see, in 3 simple steps, we created a DLL, added it to our libraries for Aurora, attached to it in our code, and utilized the 2 methods in it.
You are now well on your way to writing your very own application that will utilize DLL's with Aurora!

Zen

Nice explanation Zumwalt.

Just a thought while we are on about DLL's, Perhaps it would be a good idea to have a DLL section in the forum so that users can share there own DLL's or Static Libraries.

This is also the basic part of my plugin system, from here the subroutines call certain classes and register the plugins. Thanks to classes it is very easy to have multiple "plug-ins" within one DLL, previous plugin systems i have made with IBasic struggled to do this.

Lewis

J B Wood (Zumwalt)

October 24, 2006, 05:51:23 AM #2 Last Edit: October 24, 2006, 06:15:09 AM by zumwalt
Thats a good idea actually, Since there are a few different ways to build items in Aurora, maybe a section for each way with a 101 on how to use that build type and what it is good for in general.

I am hoping to plug in a few 101's here and there as general coding examples and instruction for new individuals to Aurora, or even existing members who need refreshers from time to time. I know I need them :)

Edit:

Actually, come to think of it Zen, this might just need moved to Tips and Tricks and have them in there instead.
Or have subsections in Tips and Tricks for tutorials in general.