How can you pass an array to a DLL? I've tried using various methods, but each time it crashes ESignal. I've created a short test program to test the DLL and everything works correctly, but once I call the DLL from ESignal it crashes. I can pass integers and doubles and it works fine, but once I pass an array---crash!!! Below are the programs I've writen in PowerBasic for creating and testing the DLL, and the EFS Script:
Any help would be greatly appreciated....
Darrell
Code:
'============================================== ' Generic DLL Template for PowerBASIC for Windows '============================================== #COMPILER PBWIN 9 #COMPILE DLL "C:\Program Files\eSignal\MyTestArray" %USEMACROS = 1 #INCLUDE "Win32API.inc" GLOBAL ghInstance AS DWORD '------------------------------------------------------------------------------- ' Main DLL entry point called by Windows... ' FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ 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 END FUNCTION '------------------------------------------------------------------------------- ' Exported function... ' FUNCTION MyFunction1 ALIAS "MyFunction1" (BYREF myParam1() AS DOUBLE) EXPORT AS DOUBLE ' test code FUNCTION = myParam1(2) ' return value to calling program END FUNCTION
Code:
'==============================================' ' Test DLL Program '============================================== #COMPILER PBWIN 9 #COMPILE EXE '-------------------------------------------------------------------- DECLARE FUNCTION MyFunction1 LIB "C:\Program Files\eSignal\MyTestArray.dll" _ ALIAS "MyFunction1" (BYREF Param1() AS DOUBLE) AS DOUBLE '-------------------------------------------------------------------- FUNCTION PBMAIN () AS LONG LOCAL lRes AS SINGLE DIM Param1(5) AS DOUBLE Param1(0)=10 Param1(1)=12 Param1(2)=14 lRes = MyFunction1(Param1()) ' call MyFunction1 in MyTestArray.dll MSGBOX "Exe result from MYTESTDLL.DLL:" + STR$(lRes) END FUNCTION
Code:
//EFS Script debugClear(); var d = new DLL("MyTestArray.dll"); var fpArray = new Array(); var myArray = new Array(); var bInit = false; function preMain() { setPriceStudy(false); setShowCursorLabel(false); setShowTitleParameters( false ); setStudyTitle("DLL Test"); setCursorLabelName("Test Value", 0); setDefaultBarFgColor(Color.red, 0); setPlotType(PLOTTYPE_LINE, 0); setDefaultBarThickness(2, 0); setComputeOnClose(); askForInput(); var x=0; fpArray[x] = new FunctionParameter("LineColor", FunctionParameter.COLOR); with(fpArray[x++]){ setName("Line Color"); setDefault(Color.green); } fpArray[x] = new FunctionParameter("ViewValue", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setName("Display Cursor Labels"); setDefault(true); } fpArray[x] = new FunctionParameter("Thickness", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Line Thickness"); setLowerLimit(1); setDefault(2); } } d.addFunction("MyEFSCallName", DLL.DOUBLE, DLL.STDCALL, "MyFunction1", DLL.DOUBLEARRAY); var xVal = 0.0; function main(Thickness, LineColor, ViewValue) { if ( bInit == false ) { setDefaultBarFgColor(LineColor, 0); setDefaultBarThickness(Thickness, 0); setShowCursorLabel(ViewValue); bInit = true; } if (getBarState()==BARSTATE_NEWBAR){ for (x=0; x<20; x++ ) { myArray[x] = close(-x); } xVal = (d.call("MyEFSCallName", myArray)); return xVal; } }
Darrell
Comment