How do you export the address of a variable or of a structure from an assembly DLL?

I know how to export a procedure. (using the export keyword), but exporting a variable eludes me.

Another thing:

Since there is an import table, can it be used to change at runtime wich function to call. If possible by the DLL itself instead of the executable?
Posted on 2001-12-21 10:24:51 by dxantos
I do not know if you can directly export a variable or structure address from a DLL.
What about exporting a function that has no parameters, but whose return value is the variable or structure address?

I hope this helps.

Sincerey,
Daniel
Posted on 2001-12-21 11:47:33 by dguzz
You don't export variables, instead what you do is export 'get' and 'set' type functions to access the internal variables. You don't 'export' a return variable, that is simply contained in the eax register. And if you are looking to have some sort of file which specifies the inbound/outbound parameters for a function call, check out how to make a type library (typelib).
Posted on 2001-12-21 14:06:22 by sluggy
It is done. A company I used to work for did this very thing. I believe they can be defined as externs. Then in your dll initialization function you can set them up. I've never done it myself, but can say that it does happen.

In this specific case I'm familiar with, the variables are given in the header file as extern pointers. Then with a pound-define so that the user doesn't have to dereference every time:

blah.h:
extern float *blahVariable;
#define blahVariable *blahVariable

I don't have the dll with me now to run dumppe on it to see how it looks, nor do I have the source code to see for sure how it's set up.
Posted on 2001-12-21 14:49:16 by cmonahan
Heres a part of an old test prog I coded to examine such things:

1. DEF file of DLL



LIBRARY

EXPORTS
Dll1Function1 @7
Dll1Function2 @8
Data1 @9 DATA
Const1 @10
Dll1Function3 @100
Dll1Function4 @101 NONAME



2. Definition in DLL



public Data1
Data1 db "japheth",cr,lf,0



3. Definition in App



.data
extern _imp_Data1:ptr byte
fstr db 10,"APP: imported data from dll1: >%s<"),10,0

.code
mov eax,_imp_Data1
invoke printf,addr fstr,eax


japheth
Posted on 2001-12-22 09:49:43 by japheth