Thanks SilentS
After going back and forth compiling and running way to many times for it to be enjoyable, I have located the problems.
1. The result must be set to a variable before being printed so it will be the proper type. Again thanks SilentS!
2. Real numbers in DBPro are equivalant with SINGLE in Powerbasic. And at the moment it seems that mixing precision types gives unexpected results. ie. I can't catch a real number from DBPro with a double precision type in Powerbasic, nor can I return with a double.
Here is a working example of both codes.
DBPro
ax# = 11.5
ay# = 11.5
az# = 10.0
bx# = 10.0
by# = 10.0
bz# = 10.0
load dll "DISTANCECALC.DLL",1
if dll call exist(1, "DIST3D") = 1
print "Accessing DLL"
` Return from DLL has to be assigned to a variable so it is type cast correctly
a# = call dll (1, "DIST3D", ax#,ay#,az#,bx#,by#,bz#)
print "a should be: ";sqrt(((ax#-bx#)^2)+((ay#-by#)^2)+((az#-bz#)^2))
print "DLL returns: ";a#
b# = call dll (1, "DIST2D", ax#,ay#,bx#,by#)
print "b should be: ";sqrt(((ax#-bx#)^2)+((ay#-by#)^2))
print "DLL returns: ";b#
else
print "DLL not called"
endif
wait key
Powerbasic
#COMPILE DLL "DISTANCECALC.DLL"
#INCLUDE "Win32API.inc"
GLOBAL ghInstance AS DWORD
'-------------------------------------------------------------------------------
' Main DLL entry point
'-------------------------------------------------------------------------------
FUNCTION DLLMAIN (BYVAL hInstance AS DWORD, _
BYVAL fwdReason AS LONG, _
BYVAL lpvReserved AS LONG) AS LONG
SELECT CASE fwdReason
CASE %DLL_PROCESS_ATTACH
ghInstance = hInstance
FUNCTION = 1 'success!
CASE %DLL_PROCESS_DETACH
FUNCTION = 1 'success!
CASE %DLL_THREAD_ATTACH
FUNCTION = 1 'success!
CASE %DLL_THREAD_DETACH
FUNCTION = 1 'success!
END SELECT
' If FUNCTION returns anything other than 1, there was a failure
END FUNCTION
'-------------------------------------------------------------------------------
' My Functions
'-------------------------------------------------------------------------------
FUNCTION DIST3D( _
BYVAL ax AS SINGLE, _
BYVAL ay AS SINGLE, _
BYVAL az AS SINGLE, _
BYVAL bx AS SINGLE, _
BYVAL by AS SINGLE, _
BYVAL bz AS SINGLE) EXPORT AS SINGLE
DIM result AS SINGLE
'Set return to -1 to signal an error
result = -1.0
'Get distance between 2 3d coordinates
result = SQR( ((ax-bx)^2) + ((ay-by)^2) + ((az-bz)^2) )
'If return = -1 then nothing got executed therefore an error occurred
DIST3D = result
END FUNCTION
FUNCTION DIST2D( _
BYVAL ax AS SINGLE, _
BYVAL ay AS SINGLE, _
BYVAL bx AS SINGLE, _
BYVAL by AS SINGLE) EXPORT AS SINGLE
DIM result AS SINGLE
'Set return to -1 to signal an error
result = -1.0
'Get distance between 2 2d coordinates
result = SQR( ((ax-bx)^2) + ((ay-by)^2) )
'If result = -1 then nothing got executed therefore an error occurred
DIST2D = result
END FUNCTION
" Base 8 is just like base 10 actually... If you're missing 2 fingers! " - Tom Lehrer