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.

DLL Talk / Accessing DBP variables from dll

Author
Message
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 28th May 2007 23:07
I've written a GetLocalTime Function to return the Current time. Currently it returns a string in the format "HH:MM:SS.mmm", but I am looking for a way to return it in the following into a predefined type.



This is the structure returned by the c++ function GetLocalTime.

I have seen g_pVariableSpace defined within GlobStruct, and when I look at this memory area within VS I can see the contents of all my variables, I just don't know how to identify the ones I want to update and if I could I don't know how to update them.

Does anyone have any ideas? Maybe someone with a bit more knowledge caould take a look.

Cheers,

Cloggy
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th May 2007 23:55
Actually, you might be able to see the contents of your globals, but not your local variables - they are stored on the stack.

Unfortunately, there's no way to get the address of a variable by name - you can use hacks (such as used by a recent DLL) to get local variables and function parameters by offset, and the same may work for globals, but nothing that I'd say was concrete enough for serious use.

The best I've been able to do is to get the address of an array item and pass that, but that won't work with a packed structure like yours. DBPro will put each part of a UDT into it's own 4-byte block, but C will pack those words against each other.

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 29th May 2007 00:47
I can return all the values as invividual strings in the function. The following works with now problem. I can stick with that for now.



I just sprintf the values directly to the variables passed and this works fine. Unfortunately this doesn't work for other variable types as they seem to be passed by value rather than reference.

Cheers,

Cloggy
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th May 2007 01:00
Yes - all variables are passed by value.

If you are going to put the data into strings, you might as well just pass back a single string. The downside to your current method is that you need to make sure that the string you are writing to is not a null pointer, and points to an area of memory that is large enough to hold the value.

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 29th May 2007 01:25
I currently return a single string. This is defined in my dll, and it set to the maximum size of the value I am returning. It's just that I was creating an analogue clock and it would be easier to have all the returned values seperate rather than use MID to split them out. The reason I wrote my own function is to get a smooth second hand rather than one that moves in 1 second increments.

As far as accessing variables, it seems strange that there is a pointer to the variable area of memory in Globstruct. I presume it is used somewhere as it would seem pointless otherwise.

Maybe an email to Lee or Mike would throw some light on it?

Cheers,

Cloggy
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th May 2007 14:08 Edited at: 29th May 2007 14:17
As IanM mentioned, it's possible to obtain the address of local variables and function parameters using a 3rd party plugin, which in the case of mine allows the user to specify a variable number, and the plugin calculates the address based on the offset of the variable on the stack. This of course isn't exactly reliable, due to the fact that the calculation needs to take into the account the size of the variables, and the fact that constants are stored on the stack (which is impossible without generating some kind of stack map at compile time). The only cases that this can be used is when the user is absolutely sure of what they are doing, and declare their variables cleanly away from constants and dim statements.

As I see it, the only way to realistically be able to access variables in a predictable way (and allow the user to specify the variables by name) is to code a preprocessor that would calculate the contents of the stack (or in the case of global variables, calculate the offset of each variable based on the size of variables before it). I'm considering this, particularly if preprocessor support is added to CodeSurge.

Another way to do what you are doing is to have the user pass a single element array defined as a particular UDT, but that's a bit hackish also.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 30th May 2007 04:39 Edited at: 30th May 2007 04:48
This does both...


Sorry, I had actually modified that to use the 64 bit time struct used by Unix and Win64. Anyway, this should do both fine.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th May 2007 15:16
If that actually compiled ( ) then yes, something like that would do the job ... except that Cloggy is trying to put the equivalent of that into a plug-in

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 30th May 2007 17:46
I had thought of the following



etc. which is find when returning something like vectors, but obviously with time values, you can be out of date by a few miliseconds by the time you read them. Then again I'm not thinking of using this for high precision timing so does it matter really.

Cheers,

Cloggy
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th May 2007 18:58
You could have the plug-in take a snapshot of the time either using a separate command, or when you read the milliseconds. Then just read the other values you require in your own time after that.

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 15th Jun 2007 15:12
I've discovered a way to do this (at least for Structures)

I got my inspiration from the array functions always passing the first element as an argument



This is my function in c++



This is How it is defined in the resource file



This is the DBPro Code



I am very pleased with this result. I can't provide the dll at the moment as it is in a test version of my D3DFunc.dll, but attached is the executable for you to try.

D3DFunc - Superfast Antialiased text & much much more

Attachments

Login to view attachments
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 16th Jun 2007 23:32 Edited at: 17th Jun 2007 00:17
I've made a further discovery.

using the following string table entry allows you to return a value directly to a variable passed as a parameter.



The function in the dll would be.



The DBP code is



The only thing is that when this function is called test contains a pointer to a area of memory initialised to null rather than the contents of the variable. I'm still trying to work out how to retrieve the contents of the actual variable.

Maybe someone with a bit more c++ knowledge would be able to progress this a bit quicker than me.

Please ignore this last post as this has already been discussed here

D3DFunc - Superfast Antialiased text & much much more
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Jun 2007 01:59
Using the * in your variable type list doesn't pass anything to your function. Your UpdateVar function should be:


What you were seeing as a pointer is just random junk from the stack.

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 17th Jun 2007 21:53
Oh well, at least passing back a structure in an array works

Have to just work out what useful things can be done with it now.

D3DFunc - Superfast Antialiased text & much much more

Login to post a reply

Server time is: 2024-11-22 21:20:48
Your offset time is: 2024-11-22 21:20:48