The two snippets below perform identical procedures, but the first is written in C++, while the second is written in C#. The comments in the C# code identify the MIL-specific differences.
class MyDisplay
{
private:
MIL_ID _dispId;
public:
MyDisplay(MIL_ID ownerSystem)
{
// Allocate the default display on the specified system.
MdispAlloc(ownerSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &_dispId);
// Set a custom title for the display window.
MdispControl(_dispId, M_TITLE, MIL_TEXT("My Display"));
}
MIL_DOUBLE GetZoomFactorX()
{
MIL_DOUBLE xFactor = 0.0;
MdispInquire(_dispId, M_ZOOM_FACTOR_X, &xFactor);
return xFactor;
}
bool GetOverlayEnabled()
{
MIL_INT overlay = MdispInquire(_dispId, M_OVERLAY, M_NULL);
return (overlay == M_ENABLE) ? true : false;
}
};
using System.Text;
using Matrox.MatroxImagingLibrary;
namespace DataTypes
{
class MyDisplay
{
private MIL_ID _dispId = MIL.M_NULL;
public MyDisplay(MIL_ID ownerSystem)
{
// The MIL_TEXT macro in C++ is replaced by a string in C#.
MIL.MdispAlloc(ownerSystem, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, ref _dispId);
// Set a custom title for the display window.
// The M_PTR_TO_DOUBLE macro in C++ is replaced by a string in C#.
MIL.MdispControl(_dispId, MIL.M_TITLE, "My Display");
}
public double ZoomFactorX
{
get
{
// The double type has the same representation in 32-bit and 64-bit
// No need to use a custom data type to write portable code.
double xFactor = 0.0;
MIL.MdispInquire(_dispId, MIL.M_ZOOM_FACTOR_X, ref xFactor);
return xFactor;
}
}
public bool OverlayEnabled
{
get
{
// Using the MIL_INT type ensures that the code will be portable
// It allows using the same code to compile a 32-bit and 64-bit
// version of the application.
MIL_INT overlay = MIL.MdispInquire(_dispId, MIL.M_OVERLAY, MIL.M_NULL);
return (overlay == MIL.M_ENABLE) ? true : false;
}
}
}
}