| Customize Help

Building a .NET application using MIL



For MIL functions and constants to be available in a managed .NET application, you must first add a reference to Matrox.MatroxImaginglibrary.dll in Visual Studio; this gives the code access to all of MIL. Once this is done, your code can use the language-specific call to include the library. Note that all MIL modules are contained in a single namespace, Matrox.MatroxImagingLibrary. The following details the procedure for referencing and including MIL in C# or Visual Basic in a managed .NET environment.

MIL inclusion procedure for .NET

To use MIL functions and constants, you must first reference Matrox.MatroxImaginglibrary.dll, and optionally, include the library in your code. To start using MIL in an existing .NET project:

  1. In Visual Studio, from the Project menu, select Add Reference.

  2. In the Add Reference dialog box, select the Browse tab.

  3. Go to the Matrox Imaging\MIL\MIL.NET directory, select Matrox.MatroxImaginglibrary.dll, and click on the OK button to add the reference.

  4. Add the following to your code to include the functions and constants in the Matrox.MatroxImagingLibrary namespace:

    Language

    Reference statement

    Visual C#

    using Matrox.MatroxImagingLibrary;

    Visual Basic

    Imports Matrox.MatroxImagingLibrary

    Note you could optionally avoid including the entire library and preface each MIL function call with [[Matrox.MatroxImagingLibrary.]MIL.MilFunction(...)].

  5. Add MIL code in your application, keeping in mind the differences of programing with the MIL.NET wrapper, which are discussed throughout this chapter.

32-bit and 64-bit applications

When using the MIL.NET wrapper, compiling an application that will run under 32-bit and 64-bit operating systems requires special consideration. Normally when programming in the .NET environment, you can compile in "Any CPU" configuration, which allows you to run applications under 32-bit or 64-bit operating systems without manually changing the code or recompiling the application. However, the MIL API, and consequently the MIL.NET wrapper, is different in 32-bit and 64-bit operating systems. A .NET application that includes MIL must be compiled for either a 32-bit or 64-bit operating system. If you need an application to work under a 32-bit and 64-bit operating system, you must compile two separate applications.

When compiling under different operating systems, the code does not necessarily have to change. The MIL_ID and MIL_INT data types are portable across 32-bit and 64-bit operating systems. Consequently, using these custom MIL data types, as opposed to the language-specific data types, allows for more portable code. See the Data types in MIL with .NET section later in this chapter for more information on MIL_ID and MIL_INT.

Calling MIL functions and constants in .NET

Once the Matrox.MatroxImagingLibrary.dll is properly referenced and accessible by your code, calling MIL functions is almost identical in .NET as it is in unmanaged C/C++. The MIL library is in a MIL.NET wrapper, and all MIL functions and constants are static members of the class. The only difference in calling a function or using a constant lies in prefacing each MIL function and each MIL constant with "MIL.", assuming you have included the library in your code as outlined in step 4 of the MIL inclusion procedure for .NET subsection.

// C++ sample function call
MbufAlloc2d(ownerSystem, 640, 480, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &_bufID);
// C# sample function call. 
// Note the 'MIL.' preface for the function name and constants
MIL.MbufAlloc2d(ownerSystem, 640, 480, 8 + MIL.M_UNSIGNED, 
                             MIL.M_IMAGE + MIL.M_PROC, ref _bufID);

Disabling compiler warnings in .NET

If you recompile a MIL application with deprecated constants and functions, compiler warnings will now typically be generated. Deprecated constants and functions should no longer be used since they could be removed in a future major release of MIL (for example, MIL 11). All code that produces warnings about deprecated features should be updated to the code's current equivalent. For more information on how to update deprecated constants and functions to the code's current equivalent, see the Compiler warnings for deprecated constants and functions subsection of the Compiling and linking section of Chapter 1: Introduction.

Deprecated MIL functions and constants in the .NET environment are denoted with the Obsolete attribute. The Obsolete attribute is a .NET feature that marks a program entity as one that is no longer recommended for use. Whenever you use a program entity marked as Obsolete, the compiler will generate a warning or an error. You can disable warnings about Obsolete features by following the procedures below. Note, however, that code with deprecated features might not compile with a future major release of MIL if you disable warnings and do not replace the code with the current standard.

Procedure for disabling compiler warnings in C#

There are two possible ways to disable compiler warnings when building an application in C#: one that disables compiler warnings caused by the Obsolete attribute for an encapsulated piece of code, and one that disables compiler warnings caused by the Obsolete attribute across the entire project.

To disable compiler warnings for a portion of your C# application (for example, a block of code that should be updated to the code's current equivalent), you can encapsulate your code with the #pragma warning directive. This is preferable to disabling the compiler warnings globally, since it will disable the compiler warnings caused by the Obsolete attribute for only a block of MIL code rather than your entire project. Encapsulate your code between the following preprocessor directives:

#pragma warning disable 612, 618  // Disable warnings for code marked as Obsolete.
// MIL Code that generates the warning
#pragma warning restore 612, 618 // Restore warnings for code marked as Obsolete.

To disable compiler warnings caused by the Obsolete attribute across the entire project, perform the following steps. Note that this will disable all compiler warnings caused by the Obsolete attribute, including constants and functions not related to MIL.

  1. Open the Project Properties dialog box in Microsoft Visual Studio, by either selecting the 'projectName' Properties item in the Project menu, or by right-clicking on the project's name in the Solution Explorer pane and selecting Properties.

  2. In the Build tab of the Project Properties dialog box, add 0612;0618 to the Suppress warnings text box.

  3. Repeat step 2 for each build configuration and platform combination.

Procedure for disabling compiler warnings in Visual Basic

When building an application using Visual Basic, it is only possible to disable compiler warnings caused by the Obsolete attribute across the entire project. To do so, perform the following steps. Note that this will disable all compiler warnings caused by the Obsolete attribute, including constants and functions not related to MIL.

  1. In the Solution Explorer pane of Microsoft Visual Studio, right-click on the project's name and select Unload Project.

  2. Right-click on the unloaded project's name in the Solution Explorer pane, and select Edit projectName.vbproj. This opens the projectName.vbproj in Visual Studio's editor pane.

  3. Find an XML element with the tag name NoWarn in the projectName.vbproj file and add 40008 to the element's list of numbers.

  4. Repeat step 3 for all elements with the tag name NoWarn.

  5. Save projectName.vbproj and close the file.

  6. Right-click on the unloaded project's name in the Solution Explorer pane, and select Reload Project.