nach ca. einer sehr intensiven Woche, ist es mir gelungen eine DLL in FreeBASIC mit CCalculateEx herzustellen. Das Hauptproblem waren natürlich (mal wieder) die Strings.
Code: Alles auswählen
' :::::::::: DLL-START ::::::::::::: '
Extern "windows-ms"
' ===== DEFINE NAMES TO INDEXES ===== ' easier to remember than numbers
' PInputs (none in this DLL)
' POutputs
const as byte path = 0
const as byte prog = 1
const as byte errx = 2
' PUser (none in this DLL)
' PStrings preparation (different from numeric variables)
const as short SI = 1001 ' SI = String Index multiplier factor
' PStrings
const as byte OStrg1 = 0
const as byte OStrg2 = 1
' other var's
STATIC SHARED AS STRING EPath, EProg ' temporary static string var's, used in CSimStart and CCalculateEx
' ===== DEFINITION OF EXTERNAL FUNCTION's/SUB's ===== '
'Function NumInputsEx () as Byte Export ' used only if configuable by CConfig
Function NumInputs () as Byte Export ' static definition
Function = 0
End Function
'Function NumOutputsEx () as Byte Export' used only if configuable by CConfig
Function NumOutputs () as Byte Export ' static definition
Function = 3
End Function
Sub GetInputName (byval Channel as Byte, byref InputName as ZString) Export
' not used
End Sub
Sub GetOutputName (byval Channel as Byte, byref OutputName as ZString) Export
Select CASE Channel
Case 0
OutputName = "$Path"
Case 1
OutputName = "$Prog"
Case 2
OutputName = "ERRx"
End Select
End Sub
Sub CSimStart (byval PInput as Double ptr, byval POutput as Double ptr, byval PUser as Double ptr) Export
EPath = ExePath + "\"
EProg = "ExePath.dll (c) ML-Enterprises, 2013" ' needs to be done once only, fill TempStrings
End Sub
SUB CCalculateEx (byval PInput as DOUBLE PTR, byval POutput as DOUBLE PTR, _
byval PUser as DOUBLE PTR, byref PStrings as ZString PTR) EXPORT
' NO TYPEDEFS needed at all ... but, see next line
' IMPORTANT! String Indexes must be multiplied with SI to work correctly
' Conclusion: the strings are really 1001 bytes (1000 bytes string + terminator)
PStrings[path * SI] = EPath ' needs to be here because of NO strings in CSimStart
PStrings[prog * SI] = EProg
POutput[path] = PStrings[path * SI]
POutput[prog] = PStrings[prog * SI]
POutput[errx] = 98765.01234 ' test for numeric out (comment out when writing *.log) see below
' writing to a file to sort out possible errors (comment it out when OK [creates a lot of 'traffic' on disk])
' dim as integer x = -1 ' set fault ... quick and dirty err checking
' VAR fnr = FREEFILE, fname = "X:\YOUR\PATH\TO\dll.log" ' adapt: 'Drive:\...\...\...\file.ext' to your settings
' ' Remark: make shure that your USER has the necessary access rights (in OS)
' x = open (fname, FOR OUTPUT, AS #fnr)
' POutput[errx] = CDbl(x) ' to 'see' if 'file open' throws an error, numeric out
' if x = 0 then ' if 'file open' is OK, 'dll.log' is written to
' print #fnr, "Path : " + PStrings[path * SI]
' print #fnr, "Prog : " + PStrings[prog * SI]
' print #fnr, "File#: " & fnr ' # stands for number, as supplied by FreeFile
' close #fnr
' end if
END SUB
Sub CSimStop (byval PInput as Double ptr, byval POutput as Double ptr, byval PUser as Double ptr) Export
' not used
End Sub
Sub CConfigure (byval PUser As Double ptr) Export
Beep ' only for test
End Sub
End Extern
' :::::::::: END OF DLL :::::::::: '