Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
17 Views

Importing a non-exported COMMON block from another DLL

So, I realize this is a bit hack-ish.  An (for my purposes) un-changeable Fortran DLL has been shipped, and it contains a certain COMMON block, as:

COMMON /TROUBLE/ AAA(30,2),BBB(30)...

All real and integer data are 64-bit, as is the target platform.

Looking at a disassembly, and knowing that a certain function call needs AAA as an argument:

  00000001808DE150: 48 8D 0D C9 36 74  lea         rcx,[93021820h]
                    12
  00000001808DE157: 48 8B 85 E8 00 00  mov         rax,qword ptr [rbp+000000E8h]
                    00
  00000001808DE15E: 4C 8B 95 F0 00 00  mov         r10,qword ptr [rbp+000000F0h]
                    00
  00000001808DE165: 49 89 4B 50        mov         qword ptr [r11+50h],rcx

I am making an educated guess that [93021820h] is the address of /TROUBLE/.

Now, the shipped DLL calls a brand new DLL that I'm developing, and this brand-new DLL needs to be able to access and modify the contents of /TROUBLE/.  My question is, what black magic do I need to add to the brand-new DLL in order for the /TROUBLE/ COMMON to be shared between the two DLLs?

If only something like this existed (if it does, please let me know!)

!DIR$ ATTRIBUTES DLLIMPORT :: /TROUBLE/ OLD.dll [93021820h]

0 Kudos
1 Reply
Highlighted
Black Belt Retired Employee
17 Views

Sorry, no such magic exists. I assume this "unchangeable" DLL has calls to some external routines, so it itself is linking to a DLL. (If it isn't, you are well and truly hosed.) Perhaps one of the calls passes the address of a COMMON variable that you can save and use as a pointer to the shared data. You won't be able to use it as a COMMON, but can turn it into a pointer to a derived type with the layout you need. Save the pointer as a module variable. This is similar to what you envision as the magic.

For COMMONs and DLLs, everything that uses the shared COMMON needs to link to a common (!) DLL that defines the COMMON.

0 Kudos