This sample demonstrates how to pass an array of strings from Visual
BASIC .NET and manipulate it in Fortran using the SafeArray and BSTR
routines in module IFCOM.
.sln fileARRAY" is not shown in boldface type in the Solution Explorer,
right-click on project "ARRAY" and select "Set as StartUp Project".Build > Clean SolutionBuild > Build SolutionDebug > Start Without Debugging or press Ctrl-F5
A form will be displayed containing a
"Push Me" button, an input values box and an output values box. The input
value box has the string values "One", "Two", "Three", ... "Twelve". When the
button is pushed, Visual BASIC will call the Fortran routine passing it an
array of the input strings.
build.bat cleanbuild.bat releasebuild.bat debugARRAY in Visual Studio IDEArrayOfVBStr.dll built from above steps under directory .\debug or .\release to the VB project output folder ARRAY\bin\Debug or ARRAY\bin\ReleaseARRAY\bin\Debug\ARRAY.exe or ARRAY\bin\Release\ARRAY.exe from the command windowARRAY" and choose Properties. In the left column, select
"Debug" > tab and check the box labeled "Enable native code debugging", close the properties page to save the changes.
test.txt is opened in the project folder and the bounds of the
array are written to the file. This demonstrates the use of the SafeArray
routines to access the bounds information.testout.txt is opened in the project folder and the contents of the
array are written to the file. This demonstrates retrieving elements from a
SafeArray and converting the BSTR string to a Fortran string. potato" appended to it so that
the modified array is returned to Visual BASIC. This demonstrates manipulating
BSTR values.The Fortran routine then returns and the Visual BASIC code writes the new array values into the output box.
Note that the Fortran code makes no assumptions about the shape of the VB array.
Array.vb and double-click on the Push Me button.