Passing of variable to DLL not taking place
Posted: Wed Jun 01, 2016 10:14 am
Below is the DLL file, compiled as "Astro2_0.dll: and the second file is the calling program. The third file is a normal function call inside a normal program.
The function computes the Julian Day. The function takes 3 variables, day as double, and month and year as integers. In calling the DLL, the day is not being passed, but in the normal function call the program is smooth.
Results of both are given below the code.
Can someone point out where I am going wrong? I would prefer not to use a Prototype.
Astro2_0.dll code
DLL Calling program - with results of the call. Notice May 15th and 31st and June 15th and 30th are same figures, so effectively ignoring day value.
Normal program with internal function - results are below the code.
The function computes the Julian Day. The function takes 3 variables, day as double, and month and year as integers. In calling the DLL, the day is not being passed, but in the normal function call the program is smooth.
Results of both are given below the code.
Can someone point out where I am going wrong? I would prefer not to use a Prototype.
Astro2_0.dll code
Code: Select all
Global JulD.d
ProcedureDLL.d JulianDay(d1.d, m.i, y.i)
Protected a.i, b.i, dd.d, mm.i, yy.i
dd = d1: mm = m: yy = y
If yy > 1582: GJ = "G": EndIf
If yy < 1582: GJ = "J": EndIf
If yy = 1582
If mm > 10: GJ = "G": EndIf
If mm < 10: GJ = "J": EndIf
If mm = 10
If dd > 14: GJ = "G": EndIf
If dd < 5 : GJ = "J": EndIf
EndIf
EndIf
If mm > 2: mm = mm + 0: yy = yy + 0: ElseIf mm = 1 Or mm = 2: yy = yy - 1: mm = mm + 12: EndIf
a = Int(yy / 100)
If GJ = "J": b = 0: Else: b = 2 - a + Int(a / 4): EndIf
JulD = Int(365.25 * (yy + 4716)) + Int(30.6001 * (mm + 1)) + dd + b - 1524.5
ProcedureReturn @JulD
EndProcedure
Code: Select all
If OpenLibrary(0, "Astro2_0.dll")
Debug "01/01/0001 - " + StrD(PeekD(CallFunction(0, "JulianDay", 1.0, 1, 1)), 1) ;1721423.5 - 1721422.5
Debug "30/04/2016 - " + StrD(PeekD(CallFunction(0, "JulianDay", 30.0, 4, 2016)), 1) ;2457508.5 - 2457478.5
Debug "15/05/2016 - " + StrD(PeekD(CallFunction(0, "JulianDay", 15.0, 5, 2016)), 1) ;2457523.5 - 2457508.5
Debug "31/05/2016 - " + StrD(PeekD(CallFunction(0, "JulianDay", 31.0, 5, 2016)), 1) ;2457539.5 - 2457508.5
Debug "15/06/2016 - " + StrD(PeekD(CallFunction(0, "JulianDay", 15.0, 6, 2016)), 1) ;2457554.5 - 2457539.5
Debug "30/06/2016 - " + StrD(PeekD(CallFunction(0, "JulianDay", 30.0, 6, 2016)), 1) ;2457569.5 - 2457539.5
Else
MessageRequester("ERROR", "Can't open Library Astro2_0", #PB_MessageRequester_Ok)
EndIf
CloseLibrary(0)
; Results of the above Call are:
;
; 01/01/0001 - 1721422.5
; 30/04/2016 - 2457478.5
; 15/05/2016 - 2457508.5
; 31/05/2016 - 2457508.5
; 15/06/2016 - 2457539.5
; 30/06/2016 - 2457539.5
Code: Select all
Procedure.d JulianDay(d.d, m.i, y.i)
Protected a.i, b.i
If y > 1582: GJ.s = "G": EndIf
If y < 1582: GJ = "J": EndIf
If y = 1582
If m > 10: GJ = "G": EndIf
If m < 10: GJ = "J": EndIf
If m = 10
If d > 14: GJ = "G": EndIf
If d < 5 : GJ = "J": EndIf
EndIf
EndIf
If m > 2: m = m + 0: y = y + 0: ElseIf m = 1 Or m = 2: y = y - 1: m = m + 12: EndIf
a = Int(y / 100)
If GJ = "J": b = 0: Else: b = 2 - a + Int(a / 4): EndIf
dd = d+h/24+i/24/60+s/24/3600
JulD.d = Int(365.25 * (y + 4716)) + Int(30.6001 * (m + 1)) + Int(d) + b - 1524.5
ProcedureReturn JulD
EndProcedure
a1.d = JulianDay(1.0, 1, 1)
b1.d = JulianDay(30.0, 4, 2016)
c1.d = JulianDay(15.0, 5, 2016)
d1.d = JulianDay(31.0, 5, 2016)
e1.d = JulianDay(15.0, 6, 2016)
f1.d = JulianDay(30.0, 6, 2016)
Debug "01/01/0001 - " + StrD(a1, 1)
Debug "30/04/2016 - " + StrD(b1, 1) + " - " + StrD(b1-a1, 0)
Debug "15/05/2016 - " + StrD(c1, 1) + " - " + StrD(c1-b1, 0)
Debug "31/05/2016 - " + StrD(d1, 1) + " - " + StrD(d1-c1, 0)
Debug "15/06/2016 - " + StrD(e1, 1) + " - " + StrD(e1-d1, 0)
Debug "30/06/2016 - " + StrD(f1, 1) + " - " + StrD(f1-e1, 0)
; Results of the above Call are:
;
; 01/01/0001 - 1721423.5
; 30/04/2016 - 2457508.5 - 736085
; 15/05/2016 - 2457523.5 - 15
; 31/05/2016 - 2457539.5 - 16
; 15/06/2016 - 2457554.5 - 15
; 30/06/2016 - 2457569.5 - 15