Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 25th Apr 2003 20:16
First a good link for those who want to get deep into dlls:
http://www.codeproject.com/dll/

I hadn't have the time for checking it, but do someone knows what happens with global variables declared in a dll or dynamic allocations? can i trust the returned pointer of a dynamic allocation commited in a dll? i intend to use the method that DB recognizes the command without the use of "call dll", so i'm afraid the data segment the dll uses - is about to be free. suggestions?

[solo]
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Apr 2003 20:44
Excellent site - I go back there every week to see whats new.

In answer to your questions:
Global variables are just global variables. Within a TPC they will maintain their values for the life of the program. Using the CALL DLL method, they maintain their values until you DELETE DLL.

You can trust pointers to dynamically allocated memory, but you should try to return the memory from within the DLL that allocated it if you are using 'malloc' otherwise you may have memory problems.

You should also make sure (for the same reason) that you allocate strings that you intend to pass to DBPro using the 'CreateDeleteString' function pointer with the global structure.

Have a look at my DLL page (follow my WWW link below) and download the source for the utility DLL.

If you have any problems, feel free to ask
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 25th Apr 2003 23:39
IanM, thanks.
I was looking at 'CreateDeleteString' function, and if i get it right, i should use it only if i put its return value, into an internal DB string variable (free the content of DB internal string variable, and hold the new string value there),
But what if i don't use a DB string variable but a DWORD ptr? i may use my own 'allocateString' function, don't i? Thats leads me to another question:
how does the '*' operator behave with a DWORD address variable in DB?
if '*' cannot (and probably it can't) cast the address to the origin C++ pointer type (for example, a float* ) then must i use yours/MrToad's PEEK method?

[solo]

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Apr 2003 00:31
Well, not in any particular order:

Yes, CreateDeleteString is *only* for passing strings between your functions and DBPro. If you want to hold ownership of your strings inside your DLL thats up to you. Just pass a pointer back cast as a DWORD:



Addresses should be held in a dword variable in DBPro.

The way that * works is that it automatically reads the correct data into your data type, so you *must* read into the correct data type - like this:



Unfortunately, you can't read a double float or a double integer.

Anyway, I've done all that for you - look at my post here - http://www.darkbasicpro.com/apollo/view.php?t=9394&b=1
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 01:07
IanM, Great.
i think i get what i need for creating a dll.

i'm creating a couple of dlls. the first for extension of RND() that works on a given range: double random(double from,double to) and also deals with doubles,negative,positive ranges/return value,

and the second that is an implementation of a stopper:
stopper start(),stopper pause(), stopper resume(),
isElapsed(time,interval), get current stopper().

when i'm done, i have no site to upload to, so i may ask your help with it

[solo]

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Apr 2003 01:20
Um ... what's a 'stopper'?

BTW, there is *nothing* to stop you creating a function named 'rnd' that accepts 2 arguments instead of 1. DBPro will handle this automatically - a fact I found out by experimentation.

If you look at my utility DLL you will find it contains several min/max functions (all differing only by the type of arguments they accept), and even a function called mid$ that uses 3 arguments.
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 01:30
a 'stopper' (in my language, hebrew) is a timer watch, for measuring time in sports activities, for example. could be usefull for time-forcing and processing upon intervals.

so i can overload DB functions, thats nice...

[solo]

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 01:44
Except I've already got a RND function that takes 2 parameters...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 01:53 Edited at: 26th Apr 2003 01:58
oh, i didn't see it on your site.
does it work for real numbers too? does it exist in your plugin list?


[solo]

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Apr 2003 02:21
Aha, I understand now

Carry on with your rnd function - it'll be good practice for a first TPC DLL.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 02:33
No, it doesn't exist in my plug-in list - I need to update that soon.
And no, RND doesn't work with floating point numbers, only with integers.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 02:46
MrTAToad,
so it wouldn't be a waste of time, after all, for creating an RND that deals with floating number range and floating number return value...


[solo]

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 03:01 Edited at: 26th Apr 2003 03:43
I'll look into it...

I've got a random floating-point number generator running. I dont think I'll be able to get it going within a range unfortunately.

The random range is between 0.0 and 1.0

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Apr 2003 04:20
Well if you can do that, you can get a range -

(RND()*(Upper-Lower))+Lower

Where Lower is the start of the range, and Upper is the top of the range
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 12:38
It might work - I'll try it later

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Apr 2003 13:29
!!! Might work? Might?
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 14:45 Edited at: 26th Apr 2003 14:46
Well, you never know... It does seem to work...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 15:00
IanM,
This is the formula, indeed.
I managed to generate a random value between 0.0 and 1.0 with steps of 1.0/MAXLONG,
but i couldn't find in MSDN any constant like 'MAXDOUBLE' so a perfect generation with steps of 1.0/'MAXDOUBLE' is beyond me, for now.
If there is any constant for maxdouble and you know it, please tell me and i will update my generator.

[solo]

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 17:15
I use RANDOM_MAX. I've nearly finished the RANDF function, which will generate a floating-point value between two ranges (>0.0 and <1.0)

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 18:41 Edited at: 26th Apr 2003 18:42
MrTAToad,
I'm afraid RAND_MAX(=0x7fff) is not enough. please look at the following function, and tell me what you think:

//return a random value between 0.0 to 32767.0/32768.0
float RANDF()
{
return (rand()%RAND_MAX)/(float)RAND_MAX;
}

...The generated numbers are in steps of 1/32768 and therefore there are only RAND_MAX+1 available random numbers...

I'm trying to implement the following:

... return ( randLONG()%MAXLONG/(float)MAXLONG );
in order to get MAXLONG available random numbers.


[solo]

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 26th Apr 2003 20:57
In that case you cant use rand, as its limit is 0 to RAND_MAX...
There are plenty of routines out there to generate long ranges..

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Apr 2003 21:25
I have managed to track down a very basic number generator that I've converted to DBPro so that anyone can use it.

The range delivered is between 0.0 (inclusive) and 1.0 (exclusive) with a resolution of 1/(2^31) - Which is what you were looking for solo

It shouldn't be too hard for you to convert to C.

solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 26th Apr 2003 22:01
IanM,
Thanks, i have my first DLL function working.

btw, i would like to explore the ARRAY structure that you used
in one of your your plugins, and add sorting of UDT ARRAY.
could you provide some details on the ARRAY structure?

[solo]

Login to post a reply

Server time is: 2026-07-10 21:40:53
Your offset time is: 2026-07-10 21:40:53