SWMM5.dll |
I trying to the use the SWMM interface file using the SWMM5.DLL routines and VB.net version 1.1.
I am undertaking testing using an input file which runs without error when run from the standard interface or with swmm_run however following the example in the interfacing guide to be able to report on simulation progress I have tried to implement Public Function RunSwmmDll (inpFile As String, rptFile As String, outFile As String) As Integer 'Long (the example function provided in the swmm5_iface.bas file)
I have successfully made calls to the following two DLL functions swmm_open successfully returns error code 0 swmm_start successfully returns error code 0 however the following line causes a crash with no error message returned from the DLL function err = swmm_step(elapsedTime)' --- extend the simulation until the next reporting time.
The only amendment I have made to the sample code is a change of all declarations of single variable to integers (the equivalent of a VB6 Single in VB.net) I am yet to have any success calling Declare Function swmm_step Lib "swmm5.dll" (elapsedTime As Double) As Integer 'Long'.
This is how the DELPHI SWMM 5 GUI code calls the SWMM5 Functions in the SWMM 5 DLL. You should try to create the equivalent functions in the VB NET code through experimentation. I am sure that there is some subtle difference in the behavoir of VB NET vs VB6, C and Delphi that is causing the DLL problems.
procedure TSimulationForm.RunSimulation;
//-----------------------------------------------------------------------------
// Makes calls to the SWMM DLL engine to perform a simulation.
// The input, report, and binary output files required by the SWMM
// engine have already been created in Fmain.pas' RunSimulation
// procedure through a call to CreateTempFiles.
//-----------------------------------------------------------------------------
var
Err: Integer; // error code (0 = no error)
S: TStringlist; // stringlist used for input data
Duration: double; // simulation duration in days
ElapsedTime: double; // elapsed simulation time in days
begin
// Save the current project input data to a temporary file
ProgressLabel.Caption := TXT_SAVING;
ProgressLabel.Refresh;
S := TStringlist.Create; // Input will be placed in a stringlist
try
Uexport.ExportProject(S); // Write input data to the stringlist
Uexport.ExportTempDir(S); // Add temp. directory name to input
S.SaveToFile(TempInputFile); // Save input to file
finally
S.Free;
end;
// Have the SWMM solver read the input data file
ProgressLabel.Caption := TXT_READING;
ProgressLabel.Refresh;
Err := swmm_open(PChar(TempInputFile),PChar(TempReportFile),
PChar(TempOutputFile));
// If there are no input errors, then initialize the simulation
if Err = 0 then
begin
ProgressLabel.Caption := TXT_CHECKING;
ProgressLabel.Refresh;
Err := swmm_start(1);
end;
// If there are no initialization errors, then...
if Err = 0 then
begin
// Get the simulation duration in days
OldDays := 1;
Duration := GetDuration;
// Gray-out the Hrs:Min display for long-term simulations
if Duration >= SHORT_TERM_LIMIT then
begin
Panel2.Font.Color := clGrayText;
DaysPanel.Caption := '0';
HoursPanel.Caption := '';
end;
ProgressLabel.Caption := TXT_COMPUTING;
// Step through each time period until there is no more time left,
// an error occurs, or the user stops the run
repeat
Application.ProcessMessages;
Err := swmm_step(ElapsedTime);
UpdateProgressDisplay(ElapsedTime, Duration);
until (ElapsedTime = 0) or (Err > 0) or (RunStatus = rsStopped);
// End the simulation and retrieve mass balance errors
swmm_end;
swmm_getMassBalErr(ErrRunoff, ErrFlow, ErrQual);
end;
// Close the SWMM solver
swmm_close;
end;