RobertVanA
03-24-2009, 05:51 PM
In Window programming it sometimes happens that one of the arguments
of the callback function acts as a pointer to a structure. In the winproc
we need access to this structure. In C language
this can be handled very easily, but with Fortran things become complicated.
An example in C-language:
LRESULT CALLBACK WndProc( , , , LPARAM lParam)
.
LPDRAWITEMSTRUCT pdis
.
pdis=(LPDRAWITEMSTRUCT) lParam
The last argument in the Callback function is the variable under consideration.
A structure is defined in the second line; in the third line the parameter lParam
is casted into the structure pdis.
Elements of the structure then can be referred to as:
pdis->hDC
pdis->rcItem
etc.
In FORTRAN there is, as far as FORTRAN 95 concerns and AFAIK no adequate
solution. A "trick" to handle such a problem in Fortran is as follows:
(obtained from a contribution of Dick Russell to the repository at the Lahey site)
the relevant lines in the Window procedures are:
INTEGER FUNCTION WndProc( , , , lParam)
USE winapi_definitions ! definitions
INTEGER,VALUE :: lParam
.
TYPE(DRAWITEMSTRUCT) :: dis,dis_function
.
dis = dis_function(val(lParam))
.
.
dis%hDC
dis%rcItem
A structure of the required type is defined (dis) and its value is obtained
by a call to dis_function with the value of lParam as argument.
The members of the structure dis are then referred to as given.
This function is specified as follows:
TYPE(DRAWITEMSTRUCT) function dis_function(hulp)
USE winapi_definitions
TYPE(DRAWITEMSTRUCT),INTENT(in) :: hulp ! inconsistent argument definition
dis_function = hulp !
RETURN
END
Needless to say that the actual argument is the value of a scalar and the
dummy argument is a structure! This clashes with the standard.
With Lahey Fortran the problem is handled as given here, but don't compile
these parts in one file and switch off the checking! Otherwise the compiler
complains and compilation breaks off.
Does anybody know a way to handle this problem so that it is in full
accordance with the Fortran 95 standard? And further, is there a way to
do it such a way that two-way communication is possible? (The
method that is given here cannot set members of the structure that
becomes available to the calling program.
Thanks!
of the callback function acts as a pointer to a structure. In the winproc
we need access to this structure. In C language
this can be handled very easily, but with Fortran things become complicated.
An example in C-language:
LRESULT CALLBACK WndProc( , , , LPARAM lParam)
.
LPDRAWITEMSTRUCT pdis
.
pdis=(LPDRAWITEMSTRUCT) lParam
The last argument in the Callback function is the variable under consideration.
A structure is defined in the second line; in the third line the parameter lParam
is casted into the structure pdis.
Elements of the structure then can be referred to as:
pdis->hDC
pdis->rcItem
etc.
In FORTRAN there is, as far as FORTRAN 95 concerns and AFAIK no adequate
solution. A "trick" to handle such a problem in Fortran is as follows:
(obtained from a contribution of Dick Russell to the repository at the Lahey site)
the relevant lines in the Window procedures are:
INTEGER FUNCTION WndProc( , , , lParam)
USE winapi_definitions ! definitions
INTEGER,VALUE :: lParam
.
TYPE(DRAWITEMSTRUCT) :: dis,dis_function
.
dis = dis_function(val(lParam))
.
.
dis%hDC
dis%rcItem
A structure of the required type is defined (dis) and its value is obtained
by a call to dis_function with the value of lParam as argument.
The members of the structure dis are then referred to as given.
This function is specified as follows:
TYPE(DRAWITEMSTRUCT) function dis_function(hulp)
USE winapi_definitions
TYPE(DRAWITEMSTRUCT),INTENT(in) :: hulp ! inconsistent argument definition
dis_function = hulp !
RETURN
END
Needless to say that the actual argument is the value of a scalar and the
dummy argument is a structure! This clashes with the standard.
With Lahey Fortran the problem is handled as given here, but don't compile
these parts in one file and switch off the checking! Otherwise the compiler
complains and compilation breaks off.
Does anybody know a way to handle this problem so that it is in full
accordance with the Fortran 95 standard? And further, is there a way to
do it such a way that two-way communication is possible? (The
method that is given here cannot set members of the structure that
becomes available to the calling program.
Thanks!