Home |
RTTarget-32 Programming Manual Running Win32 Programs without Win32 Init Command Running a Program on the Target Compiling and Linking with On Time RTOS-32 |
Init CommandUsing the Init command, a function can be defined that will be executed before control is passed to the program's entrypoint: Init [ModuleName.]FunctionName FunctionName must be the name of an exported function without any parameters. If ModuleName. is not specified, the function is assumed to reside in the main program. Otherwise, ModuleName must specify the main program's .EXE file name or the name of a DLL specified in a previous DLL command. Function name matching is case sensitive; module names are not. Exporting a function is achieved using the __export keyword for Borland, with _declspec(dllexport) for Microsoft Visual C/C++, or listing them under the EXPORTS keyword in Delphi. Alternatively, a .DEF file can also be used for C/C++ programs. Please consult your compiler's documentation or the RTTarget-32 examples for details. Some important restrictions apply to Init functions: since they execute prior to the run-time system's initialization, they cannot use run-time system functions that require the startup code to have been executed. For example, an Init function cannot use heap allocation or file I/O functions. In addition, an Init function cannot permanently change uninitialized data, since the startup code of the run-time system (which executes after the Init function) will set all uninitialized data to zero. However, initialized global data can be changed and all such changes will be preserved. Init functions are useful for initializations required for the run-time system. For example, the installation of a floating point emulator must be done in an Init function because the run-time system performs floating point operations in its startup code. Another application could be extending the program's heap using RTCMOSExtendHeap. Here is an example of an Init function: #ifdef _MSC_VER _declspec(dllexport) void MyInitFunction(void) #else void __export __cdecl MyInitFunction(void) #endif { int Pages; RTSetFlags(RT_MM_VIRTUAL, 1); // force virtual memory manager Pages = RTCMOSExtendHeap(); // extend the heap RTDisplayString("Heap extended by "); RTDisplayInt(Pages*4); RTDisplayString("k bytes.\n"); RTEmuInit(); // initialize emulator RTDisplayString("Emulator is up and running!\n"); } For Microsoft Visual C/C++, the configuration file must contain the line: Init MyInitFunction For Borland, use: Init _MyInitFunction
|