- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to create a DLL which contains data to be shared between programs. I do not, however, want the calling units be able to change the content of my DLL data. How do I do this?
For instance, the following will create my DLL and the import *.lib library; but the integerI can be changed by the units referring to this DLL.
Now, if I declare the integerI as a parameter, the *.lib is not generated.
How can I protect my DLL data?
Thanks,
Olivier
For instance, the following will create my DLL and the import *.lib library; but the integerI can be changed by the units referring to this DLL.
[fortran]MODULE MODULE_DLL IMPLICIT NONE !DEC$ ATTRIBUTES DLLEXPORT :: I INTEGER :: I = 10 END MODULE MODULE_DLL[/fortran]
Now, if I declare the integerI as a parameter, the *.lib is not generated.
How can I protect my DLL data?
Thanks,
Olivier
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't export the variable. Instead export a function/subroutine which "gets" the value of the variable.
Les
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A parameter is not a variable - it is a "named constant". As such, it has no physical representation and cannot be exported or even linked against statically.
I agree that it seems that access routines are what is needed here. Fortran doesn't have the equivalent of C's "const" attribute, though if access to the variable is through a module you can give it the PROTECTED attribute and the compiler will generally disallow assignments from outside the module.
I agree that it seems that access routines are what is needed here. Fortran doesn't have the equivalent of C's "const" attribute, though if access to the variable is through a module you can give it the PROTECTED attribute and the compiler will generally disallow assignments from outside the module.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve,
So, I'll guess I will just write an access routine. In this case, my question is the following: is there any CPU time penalty associated with a DLL function call?
For instance, assume that my DLL contains the function PI, defined as:
REAL(KIND=DP) FUNCTION PI
PI = 4.0_DP*ATAN(1.0_DP)
END FUNCTION PI
Now, in the unit calling this DLL, is suppose I can treat this function as if it were a variable in the unit scope:
A = 2.0_DP*PI
CALL ANOTHER_SUB(PI,SOME_OTHER_ARGUMENT)
Will this be efficient though? If not, I guess I can import all required constants/data at the beginning of my code and store them in a module used by my code subroutines.
Olivier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have to treat it as a function call, not a variable. In other words, PI(), not just PI.
If these are truly constants, then declare them as PARAMETER constants in a module and USE the module. Then those constants will be visible and it won't matter if you're using a DLL or not.
If these are truly constants, then declare them as PARAMETER constants in a module and USE the module. Then those constants will be visible and it won't matter if you're using a DLL or not.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page