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 / Sharing variables between dlls

Author
Message
Nemo
21
Years of Service
User Offline
Joined: 31st Oct 2002
Location: Bangor, Northern Ireland
Posted: 24th Oct 2009 22:16
Hi there,

I have been building a few dlls for dbpro, just sort of trying to find out what is possible and what isn't for now. I'm using visual c++ 2008 express.

I thought it might be handy to be able to pass variables between dlls so i had a look around the internet and found __declspec ( dllexport ) and __declspec ( dllimport ).

Some sources say that you can export a variable from one dll and import it in another by using the above but i have not been able to make it work.

The dll that exports the variable compiles fine but the one that is supposed to import it does not, it gives the following error:

unresolved external symbol "__declspec(dllimport) int rog" (__imp_?rog@@3HA)

I have this in the exporting dll:
#define DLLEXPORT __declspec(dllexport)
DLLEXPORT int rog;

And i have this in the importing dll:
#define DLLIMPORT __declspec(dllimport)
DLLIMPORT int rog;

I only really started with this stuff so it's likely to be something obvious to those who know about these things.

Any comments would be much appreciated.

In the future we will not spank the monkey, the monkey will spank us.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Oct 2009 23:30
There are 3 methods, the 3rd of which is what you are attempting to use.

First method: Write a function that returns the addresses of the variables in your donor DLL then use LoadLibrary & GetProcAddress to get the address of the function and call it.

Second method: Export your variables in your donor DLL, then use LoadLibrary & GetProcAddress to get the address of the variables,

Third method: Ensure that you link the .lib file produced when you compile your donor DLL with your new DLL.

There are issues with method 3 - if your donor DLL is not available for any reason (such as DBPro didn't include it in the compiled exe), then your program will crash at load time.

With the other 2 methods, you can at least take some action if the DLL is not available.

Nemo
21
Years of Service
User Offline
Joined: 31st Oct 2002
Location: Bangor, Northern Ireland
Posted: 31st Oct 2009 13:44 Edited at: 31st Oct 2009 13:47
Hi, thanks for the help.

I got it working using method 2 but once i got it working the commands from the donor dll were no longer available in dbpro. Is that normal behavior? I thought maybe it was because the dll that i loaded the donor dll into was unloading the donor dll after using it or something.

I have another small confusion about the string table.

In the following the help file says %S% is describing the input:
PRINT TEXT%S%?PrintText@@YAXPAD@Z%String

Thats fine and is working for me but then we have this:
GET VALUE[%L%?GetValue@@YAHXZ
The help file says you dont need to have an input parameter description for an expression if there arent any.

Now i was trying to return a float using the method in the help file and kept getting like 1000298376 instead of the expected test value of 23. Eventually i thought maybe the %L% in the expression above is specifying the type of the return value so i put %F% in the string table for my function and it worked. So the %L% is the return type then? It doesn't say in the help file as far as i can see so i have to ask.

Also, if it is the return type how do you make a string table entry for a function that has parameters and returns a value?

Cheers

Nemo

In the future we will not spank the monkey, the monkey will spank us.
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Nov 2009 02:11 Edited at: 1st Nov 2009 02:12
The letters equate to types.

L = integer
F = float
D = boolean/byte/word/dword
O = double float
R = double integer
H = array
X = any type
0 = No parameters and no return value

To make your command return a value you put a [ after the command name. If you do that, then it means that the first letter is the type of the return value. The others are the types of the parameters.

Cloggy
19
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 2nd Nov 2009 11:59
You return a float like this



The string table entry reads like this



IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Nov 2009 14:14
Quote: "once i got it working the commands from the donor dll were no longer available in dbpro. Is that normal behavior?"

Yes. The default behaviour is for DBPro to only include the DLL's that directly contain the commands/functions you use in your BASIC program.

It's fairly easy to override that though and get DBPro to include any DLL into the compiled exe:


Just plug the list of DLL's that you need including into that 'Dependencies' array, and those DLL's will be included.

Login to post a reply

Server time is: 2024-04-19 18:35:20
Your offset time is: 2024-04-19 18:35:20