Integrate a .NET Assembly Into a Visual Basic Application
To create the component for this example, see the first several steps in Generate .NET Assembly and Build .NET Application. After you build the
MagicSquareComp component, you can build an
application that accesses the component as follows.
For this example, the application is
You can find
The program listing is as follows.
The application you build from this source file does the following:
Lets you pass a dimension for the magic square from the command line.
Converts the dimension argument to a MATLAB® integer scalar value.
Declares variables of type
MWNumericArrayto handle data required by the encapsulated
For information about these data conversion classes, see the MWArray Class Library Reference, which is also available in the
matlabrootrepresents your MATLAB installation folder.
Creates an instance of the
makesquaremethod, which belongs to the
makesquaremethod generates the magic square using the MATLAB
Displays the array elements on the command line.
Build the application using Visual Studio® .NET.
MagicSquareVBAppfolder contains a Visual Studio .NET project file for each example. Open the project in Visual Studio .NET for this example by double-clicking
MagicSquareVBApp.vbprojin Windows® Explorer.
Add a reference to the
MWArraycomponent, which is
If necessary, add a reference to the
MagicSquareCompcomponent, which is in the
Build and run the application in Visual Studio.NET.