For Programmers: Free Programming Magazines  


Home > Archive > Fortran > October 2006 > Re: Unhandled exception in SWilk.exe (SWilk2.dll) (0 xC0000005) :









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Unhandled exception in SWilk.exe (SWilk2.dll) (0 xC0000005) :
Craig Powers

2006-10-31, 7:04 pm

Athena wrote:
>
> I have created a Fortran dll. I am trying to call it from a vb6 program.
> When the program calls the dll subroutine I get "Unhandled exception in
> SWilk.exe (SWilk2.dll) (0 xC0000005) : Access violation" error. It is
> possibly argument mismatch, but I cannot locate it. Could anyone help me
> please? Thank you.
>
> The partial VB calling program and Fortran program listings are shown
> below:



> Dim init As Long
> Dim n As Long
> Dim n1 As Long
> Dim n2 As Long
> Dim ifault As Long
> Dim w As Double
> Dim pw As Double
>
> Dim i As Integer
>
> ReDim x(1 To n) As Double
> ReDim a(1 To n) As Double
>
> Call SWilk(init, x(1), n, n1, n2, a(1), w, pw, ifault) <--------------Error
>
> ----------VB Bas file-----------------------------------
>
> Declare Sub SWilk Lib "C:\WINDOWS\SYSTEM32\SWDLL2.dll" _
> (init As Long, x As Double, n As Long, n1 As Long, _
> n2 As Long, a As Double, w As Double, pw As Double, _
> ifault As Long)


This side is sensible, but disagrees with the F90 types. I'm going to
assume that the F90 side is correct, in which case, you need to change
the Doubles to Singles.

> ------------Fortran 90 file------------------------------------------
> SUBROUTINE SWilk (init, x, n, n1, n2, a, w, pw, ifault)
>
> !DEC$ ATTRIBUTES DLLEXPORT::SWilk
> !DEC$ ATTRIBUTES ALIAS:'SWilk'::SWilk
>
> ! ALGORITHM AS R94 APPL. STATIST. (1995) VOL.44, NO.4
>
> ! Calculates the Shapiro-Wilk W test and its significance level
>
> ! ARGUMENTS:
> ! INIT Set to .FALSE. on the first call so that weights A(N2) can be
> ! calculated. Set to .TRUE. on exit unless IFAULT = 1 or 3.
> ! X(N1) Sample values in ascending order.
> ! N The total sample size (including any right-censored values).
> ! N1 The number of uncensored cases (N1 <= N).
> ! N2 Integer part of N/2.
> ! A(N2) The calculated weights.
> ! W The Shapiro-Wilks W-statistic.
> ! PW The P-value for W.
> ! IFAULT Error indicator:
> ! = 0 for no error
> ! = 1 if N1 < 3
> ! = 2 if N > 5000 (a non-fatal error)
> ! = 3 if N2 < N/2
> ! = 4 if N1 > N or (N1 < N and N < 20).
> ! = 5 if the proportion censored (N - N1)/N > 0.8.
> ! = 6 if the data have zero range.
> ! = 7 if the X's are not sorted in increasing order
>
> ! Auxiliary functions
>
> ! REAL :: ppnd, alnorm, poly
>
> ! Fortran 90 version by Alan.Miller @ vic.cmis.csiro.au
> ! Latest revision - 4 December 1998
>
> IMPLICIT NONE
>
> LOGICAL, INTENT(IN OUT) :: init
> REAL, INTENT(IN) :: x(:)
> INTEGER, INTENT(IN) :: n
> INTEGER, INTENT(IN) :: n1
> INTEGER, INTENT(IN) :: n2
> REAL, INTENT(OUT) :: a(:)
> REAL, INTENT(OUT) :: w
> REAL, INTENT(OUT) :: pw
> INTEGER, INTENT(OUT) :: ifault


Declaring x and a as assumed shape (:) means that VF expects you to pass
it an array descriptor, but you are passing an array element. The
correct thing to do here is to either declare the shape (which you can
do because you pass in the extent n) or declare them assumed size (*),
which you can do PROVIDED THAT the code works with them via loops and
does not attempt to discover the upper bound. I think you'd be better
to do the former, i.e.

REAL, INTENT(IN) :: x(n)
REAL, INTENT(OUT) :: a(n)


(If you really want to, I think VF documents their descriptor format,
which would probably allow you to construct one on the VB side and leave
the declarations in the Fortran side as assumed shape, but this is
highly nonportable, potentially even from one version of VF to another.)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com