I am trying to connect a classic System Dynamics tool (Vensim DSS) with Mathematica using a DLL that is included in Vensim DSS. Reading though the instructions on how to define DLL functions on how to declare arguments - here strings - I found that if there are [out] strings one should use the .NET class System.Text.StringBuilder.
So applying the advice given will look like this:
(* definitions *)
$maxBufLen = 1000;
strOutput = NETNew["System.Text.StringBuilder", $maxBufLen];
vensimGetInfo = DefineDLLFunction["vensim_get_info", vensimDLL,
"int", {"int", "System.Text.StringBuilder", "int"}];
(* usage *)
infoWanted = 3; bufLen = $maxBufLen;
vensimGetInfo[infoWanted, strOutput, bufLen];
strOuput@ToString[]
Unfortunately this only works properly for a single string and some information will be returned by the DLL function as a series of null terminated strings that is finally ended by a double null. In such a case the above procedure will only return the first string omitting the rest.
What can be done?
System.Text.StringBuilder
does not support this type of string and something else should be used instead. I personally have no experience with .Net, so I will let someone else make the suggestion as to what that should be. $\endgroup$