Re: Unhandled exception in SWilk.exe (SWilk2.dll) (0 xC0000005) : Access violation error in Fortran dll.




Athena wrote:
Hello,

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:

Athena

--------------VB form file----------------------------
Option Explicit
Option Base 1

Private Sub Command1_Click()

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

Open "D:\Example2a.dat" For Input As #1

n = 36
n1 = n
n2 = n / 2

ReDim x(1 To n) As Double
ReDim a(1 To n) As Double

For i = 1 To n
Input #1, x(i)
Next

Close #1

init = 0

' Apply the Shapiro-Wilks test

Call SWilk(init, x(1), n, n1, n2, a(1), w, pw, ifault) <--------------Error

Print "Error =", ifault
Print "Shapiro-Wilk W = ", w
Print "Shapiro-Wilk pvalue = ", pw

End Sub

----------VB Bas file-----------------------------------
Option Explicit

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)

------------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

VB Double does not match DVF/CVF Real. (Unless there is a compiler
switch that sets default real to "double precision".)

.



Relevant Pages