MIL features data types and functions that can improve your application's portability and operating system independence.
In addition to the standard data types available in C and C++, MIL introduces the following predefined data types, to ensure better compatibility and portability of MIL applications under different operating systems:
MIL_ID. Specifies a value that is a MIL identifier. The MIL_ID data type is used to identify objects (for example, buffers, systems, and contexts) which are allocated using MIL within an application.
MIL_INT. Specifies a value that is an integer. The MIL_INT data type is used as a supplement to the more conventional long and int data types. The MIL_INT data type is a 32-bit value on a 32-bit operating system, and a 64-bit value on a 64-bit operating system.
MIL_UINT. Specifies a value that is an unsigned integer. Its data depth is the same as that of the MIL_INT data type.
MIL_DOUBLE. Specifies a value that is a double precision, floating-point number.
MIL_FLOAT. Specifies a value that is a single precision, floating-point number.
In addition to the MIL_INT and MIL_UINT data types, MIL also has signed and unsigned, fixed length versions of these data types: MIL_INT8, MIL_UINT8, MIL_INT16, MIL_UINT16, MIL_INT32, MIL_UINT32, MIL_INT64, and MIL_UINT64.
MIL also introduces the following predefined data types, to ensure better compatibility and portability of applications regardless of whether they are compiled for ASCII or Unicode character sets:
MIL_TEXT_CHAR. Specifies an array of characters. The MIL_TEXT_CHAR data type is used as a replacement for the more conventional char data type.
MIL_TEXT_PTR. Specifies a pointer to an array of characters. The MIL_TEXT_PTR data type is used as a replacement for the more conventional char* data type.
MIL_CONST_TEXT_PTR. Specifies a pointer to an array of constant characters. The data type is used as a replacement for the more conventional const char* data type.
MIL_WINDOW_HANDLE. Specifies the handle to a window. The data type is used as a replacement for the more conventional HWND data type in Windows and the Window data type when using the Xlib library in Linux.
There is a macro called MIL_TEXT which converts the provided string to the proper encoding (ASCII or Unicode) for the application. Its syntax is: MIL_TEXT("Text to be converted.").
When using void pointers, it is possible to make a mistake and pass a value with the wrong data type. These errors can cause unexpected behavior such as: stack corruption, array overflow, uninitialized returned data, and segmentation faults. MIL includes the M_MIL_USE_SAFE_TYPE extension to help you find these errors.
Note that this extension is not supported under Linux.
When the M_MIL_USE_SAFE_TYPE extension is enabled, an error message is returned if the data type of the variable whose address is passed to a void pointer parameter does not match the expected data type. By default, the M_MIL_USE_SAFE_TYPE extension is enabled when compiling in debug mode.
Note that the M_MIL_USE_SAFE_TYPE extension is only available if you are using a C++ compiler under Windows.
You might want to skip the verification performed by the M_MIL_USE_SAFE_TYPE extension if:
The data type of a value is unknown at the time the function is called. This typically occurs when the MIL function is wrapped inside another function in the application. For example:
MIL_INT UserWrapperAroundMbufInquire(MIL_ID BufId, MIL_INT64 InquireType, void *UserVarPtr){
return MbufInquire(BufId, InquireType, UserVarPtr);
}
The data type of the value passed to a function is not one of the expected data types accepted by a function (for example, when a custom data type is defined in the application).
MIL_INT8 *Data = (MIL_INT8 *)malloc(sizeof(MIL_DOUBLE) / sizeof(MIL_INT8));
MmodGetResult(ResultId, M_GENERAL, M_NUMBER, Data);
Number = *((double*)Data);
free(Data);
To disable the M_MIL_USE_SAFE_TYPE extension entirely, include the #define M_MIL_USE_SAFE_TYPE 0 statement before the #include <mil.h> statement in the application code. When the extension is excluded, all MIL functions are called without any data type verification.
In addition to the functions available in the C/C++ standard library, MIL introduces the following functions to ensure better compatibility and portability of applications regardless of whether they are compiled for ASCII or Unicode character sets:
Function in the C/C++ standard library |
Portable MIL version of the function |
Description |
abs |
MIL_INT MosAbs(MIL_INT n) |
Calculates the absolute value of "n". |
getch |
MIL_INT MosGetch() |
Reads a character or keystroke from the standard input (keyboard). After a keystroke is read, the application instantly resumes. |
getchar |
MIL_INT MosGetchar() |
Reads a character from the standard input (keyboard). After a keystroke is read, the application waits for the Enter key to be pressed before resuming. |
kbhit |
MIL_INT MosKbhit() |
Returns a non-zero value once a keystroke is read. |
main |
MIL_INT MosMain() |
Specifies the first function to execute. |
printf |
MIL_INT MosPrintf(MIL_CONST_TEXT_PTR FormatString, Arg1, Arg2, …) |
Prints formated data to the console. The FormatString parameter is a MIL_TEXT string that can optionally contain format specifiers that will be replaced with the subsequent arguments (Arg1, Arg2, ...). Format specifiers are introduced by the "%" character within the FormatString value. For example, the following code: MosPrintf(MIL_TEXT("A character: %c and an integer: %d"), 'b', 523); outputs the following sentence to the console: A character: b and an integer: 523. |
sleep |
MIL_INT MosSleep(MIL_INT waitTime) |
Suspends an application for the specified period of time. |
sprintf |
MIL_INT MosSprintf(array of type MIL_TEXT_CHAR DstArrayPtr, MIL_CONST_TEXT_PTR FormatString, Arg1, Arg2, …) |
Writes formatted data to a string. The DstArrayPtr parameter specifies the array of characters in which to store the formatted data as a string. The FormatString parameter is a MIL_TEXT string that can optionally contain format specifiers that will be replaced with the subsequent arguments (Arg1, Arg2, ...). Format specifiers are introduced by the "%" character within the FormatString value. For example, the following code: MosSprintf(String, MIL_TEXT("A character: %c and an integer: %d."), 'b', 523); saves the following sentence in DstArrayPtr: A character: b and an integer: 523. |
strcat |
MIL_INT MosStrcat(MIL_TEXT_PTR strDestination, MIL_INT size, MIL_TEXT_PTR strSource) |
Joins strings. |
strcmp |
MIL_INT MosStrcmp(MIL_TEXT_PTR string1, MIL_TEXT_PTR string2) |
Compares two strings. |
strcpy |
MIL_INT MosStrcpy(MIL_TEXT_PTR strDestination, MIL_INT size, MIL_TEXT_PTR strSource) |
Copies characters of one string to another. |
strlen |
MIL_INT MosStrlen(MIL_TEXT_PTR str) |
Calculates and returns the length of a string. |
strlwr |
MIL_INT MosStrlwr(MIL_TEXT_PTR str) |
Converts a string to lowercase. |
strupr |
MIL_INT MosStrupr(MIL_TEXT_PTR str) |
Converts a string to uppercase. |
For more information on the above-mentioned functions of the C/C++ standard library, refer to MSDN.