- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi to all,
In the past I have successfully exported variables defined within a DLL using the "DLL Export" directive. Despite of this, right now I'm having trouble exporting some variables with the parameter attribute. As an example consider the following code:
Compiling and linking as a DLL and running the "dumpbin" with /exports switch reveals:
As one can see the max_ib2 and max_jb1 are not listed and consequently they were not exported. So I ask, is it possible to export parameters? Thank you in advance.
Pedro
In the past I have successfully exported variables defined within a DLL using the "DLL Export" directive. Despite of this, right now I'm having trouble exporting some variables with the parameter attribute. As an example consider the following code:
[fortran]module exports
implicit none
logical :: logical_wait=.True.
!dec$ attributes dllexport :: logical_wait
integer :: app_run_count=-1
!dec$ attributes dllexport :: app_run_count
integer, parameter :: max_ib2 = 40,max_jb1 = 40 !not exported
!dec$ attributes dllexport :: max_ib2,max_jb1
integer :: ib2_shared = -1,jb1_shared=-1
!dec$ attributes dllexport :: ib2_shared,jb1_shared
real, dimension(max_ib2,max_jb1) :: x0_shared=1.5,y0_shared=1.5,z0_shared=1.5
!dec$ attributes dllexport :: x0_shared,y0_shared,z0_shared
end module exports[/fortran]
Compiling and linking as a DLL and running the "dumpbin" with /exports switch reveals:
[bash]Dump of file export_problem.dll
File Type: DLL
Section contains the following exports for export_problem.dll
00000000 characteristics
4D48A66E time date stamp Wed Feb 02 00:33:50 2011
0.00 version
1 ordinal base
7 number of functions
7 number of names
ordinal hint RVA name
1 0 00007B08 EXPORTS_mp_APP_RUN_COUNT = _EXPORTS_mp_APP_RUN_COUNT
2 1 00007B04 EXPORTS_mp_IB2_SHARED = _EXPORTS_mp_IB2_SHARED
3 2 00007B00 EXPORTS_mp_JB1_SHARED = _EXPORTS_mp_JB1_SHARED
4 3 00007B0C EXPORTS_mp_LOGICAL_WAIT = _EXPORTS_mp_LOGICAL_WAIT
5 4 00006200 EXPORTS_mp_X0_SHARED = _EXPORTS_mp_X0_SHARED
6 5 00004900 EXPORTS_mp_Y0_SHARED = _EXPORTS_mp_Y0_SHARED
7 6 00003000 EXPORTS_mp_Z0_SHARED = _EXPORTS_mp_Z0_SHARED
Summary
5000 .data
1000 .rdata
1000 .reloc
1000 .rsrc
1000 .text
1000 .trace[/bash]
As one can see the max_ib2 and max_jb1 are not listed and consequently they were not exported. So I ask, is it possible to export parameters? Thank you in advance.
Pedro
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no such thing in Fortran as "variables with the parameter attribute". A declaration that includes the PARAMETER attribute declares a "named constant", which is meaningful only during Fortran compilation. This is not something that can be DLLEXPORTed.
You can DLLEXPORT initialized variables (no PARAMETER), but this does not prevent them from being modified during execution.
You can DLLEXPORT initialized variables (no PARAMETER), but this does not prevent them from being modified during execution.
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no such thing in Fortran as "variables with the parameter attribute". A declaration that includes the PARAMETER attribute declares a "named constant", which is meaningful only during Fortran compilation. This is not something that can be DLLEXPORTed.
You can DLLEXPORT initialized variables (no PARAMETER), but this does not prevent them from being modified during execution.
You can DLLEXPORT initialized variables (no PARAMETER), but this does not prevent them from being modified during execution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
I agree with you. I was a wrong when I wrote "variables with the parameter attribute". Despite of this I'm out of luck exporting this constants... Thank you for your answer.
There is another way that allows exporting and at the same time protects the variable from being modified?
Pedro
I agree with you. I was a wrong when I wrote "variables with the parameter attribute". Despite of this I'm out of luck exporting this constants... Thank you for your answer.
There is another way that allows exporting and at the same time protects the variable from being modified?
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not aware of a way of DLLEXPORTing a value that prevents it from being modified. Let me suggest that rather than using DLLEXPORTed variables, you define a "GET" function that returns the value, which could be a PARAMETER. This will protect it from being modified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve and Pedro
Perhaps "Protected" may be used in this case? The test case below works. The dependency walker does show variable JJ being exported and the main program cannot modify it directly.
Abhi
-----
Perhaps "Protected" may be used in this case? The test case below works. The dependency walker does show variable JJ being exported and the main program cannot modify it directly.
Abhi
-----
[fortran] Module OM
Implicit None
!DEC$ ATTRIBUTES DLLEXPORT :: JJ
Integer, Protected :: JJ = 10
Contains
Subroutine Set(j)
!DEC$ ATTRIBUTES DLLEXPORT :: Set
Integer, Intent(IN) :: j
JJ = j
End Subroutine Set
Subroutine Get(j)
!DEC$ ATTRIBUTES DLLEXPORT :: Get
Integer, Intent(OUT) :: j
j = JJ
End Subroutine Get
End Module OM
Program Test_ProtectedFromDLL
Use OM
Implicit None
Print *, JJ
End Program Test_ProtectedFromDLL [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
PROTECTED simply makes the Fortran compiler enforce language rules when it sees the attribute. It does not put the variable in read-only storage (because the defining module is allowed to modify it.) Once you DLLEXPORT the variable, there is no protection.
The only thing that comes to mind is quite awkward - a separate DLL that contains only the variables to be exported and a linker directive to mark the .DATA image section R (for read-only).
The only thing that comes to mind is quite awkward - a separate DLL that contains only the variables to be exported and a linker directive to mark the .DATA image section R (for read-only).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve and abhimodak for your suggestions.
I have already implemented a subroutine that returns my parameters and it works fine. It' s probably the best and simple solution to achieve what I want. Thank you again.
Pedro
I have already implemented a subroutine that returns my parameters and it works fine. It' s probably the best and simple solution to achieve what I want. Thank you again.
Pedro
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