News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How do I address a extern structure in a DLL

Started by alanabbott, July 20, 2008, 11:00:56 PM

Previous topic - Next topic

alanabbott

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.

hutch--

Alan,

Make the data PUBLIC in the source and use the EXTERNDEF notation for the seperate module that wants access to it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

japheth

> 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.


hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

alanabbott

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

japheth

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



PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website