The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: alanabbott on July 20, 2008, 11:00:56 PM

Title: How do I address a extern structure in a DLL
Post by: alanabbott on July 20, 2008, 11:00:56 PM
The calling function would have to pass the address of the structure in a parameter or on the stack.
But in the case of the DLL, to be loaded dynamically not linked,
how do I indicate to assembler that all in the external structure is to be addressed through the address furnished by the caller.
Title: Re: How do I address a extern structure in a DLL
Post by: hutch-- on July 21, 2008, 01:05:38 AM
Alan,

Make the data PUBLIC in the source and use the EXTERNDEF notation for the seperate module that wants access to it.
Title: Re: How do I address a extern structure in a DLL
Post by: japheth on July 21, 2008, 05:24:53 AM
> Make the data PUBLIC in the source and use the EXTERNDEF notation for the seperate module that wants access to it.

Using PUBLIC/EXTERNDEF are the correct strategy if two modules are statically linked. If there are two separate binaries, it's "less" helpful.

> how do I indicate to assembler that all in the external structure is to be addressed through the address furnished by the caller.

Use a pointer. Example for Masm:


;1. write an include file, containing your STRUCT (i.e. name is MYSTRUCT):
MYSTRUCT STRUCT
field1 dd ?
; ... more fields
MYSTRUCT ENDS
;2. in the calling module, define a variable with this type
   myvar MYSTRUCT <>
;   and to pass the address of myvar to another module do
   push offset myvar
   call myproc
;3. in the called module, define the PROC
   myproc PROC parm1:ptr MYSTRUCT
;4. inside <myproc>, access the contents of parm1 with code like this:
   mov edx,parm1
   mov eax,[edx].MYSTRUCT.field1


to make myproc accessible for external modules, the proc must be "exported". For Win32 this is usually done by a .DEF file supplied to the linker.

Title: Re: How do I address a extern structure in a DLL
Post by: hutch-- on July 21, 2008, 09:54:01 AM
To get data in a DLL from the caller, pass a single address of a table that has the offsets of the callable procedures in it. You will need to make the calls corectly from the DLL end but using a table allows you to keep extending the available data without having to change the procedure call in the DLL.
Title: Re: How do I address a extern structure in a DLL
Post by: alanabbott on July 21, 2008, 02:14:14 PM
ASSUME seams to be the answer to my quest, making available an external structure to dynamically loaded DLLs and their work areas to make then totally re-entrant.
May be I did not express what I was looking for, it actually was an equivalent to USING in /370 Assembler.

Many thanks, Alan
Title: Re: How do I address a extern structure in a DLL
Post by: japheth on July 21, 2008, 03:42:03 PM
Quote from: alanabbott on July 21, 2008, 02:14:14 PM
ASSUME seams to be the answer to my quest, making available an external structure to dynamically loaded DLLs and their work areas to make then totally re-entrant.
May be I did not express what I was looking for, it actually was an equivalent to USING in /370 Assembler.

Don't worry, you expressed yourself very comprehensible. There's a "small" risk that your assumption about ASSUME and how it works is "premature". But you'll find the proper solution, I'm sure ...  :U


Title: Re: How do I address a extern structure in a DLL
Post by: PBrennick on July 22, 2008, 11:11:57 AM
Using ASSUME makes the assembler behavior in a certain way that may not be desirable through the entire code. Use the following example as a guide.


    assume  esi:ptr CPLINFO
    mov     [esi].lData, 0
    mov     [esi].idIcon, 200
    mov     [esi].idName, 3000
    mov     [esi].idInfo, 3001
    assume  esi: nothing


If I remember correctly, you do not need to do that with USING (been a lot of years).

-- Paul