Home |
The ISO 9660 File System Structure The exFAT File System Structure RTFiles-32 in Embedded Applications Win32 API Emulation |
Win32 API EmulationWhen RTFiles-32 is used with RTTarget-32, RTTarget-32's installable file system feature is used to redirect all Win32 file I/O API calls to RTFiles-32. More information about configuring the installable file system for use with RTTarget-32 is given in section Advanced Topics, Win32 API Emulation with RTTarget-32 and in the RTTarget-32 Programming Manual. RTFiles-32 supports the following Win32 API functions:
Win32 File HandlesOne important concept of the Win32 API are handles. The number of available Win32 handles is limited but can be changed (please refer to the RTTarget-32 Programming Manual, section Win32 Handles for details). It is very important that all handles are closed when no longer needed to avoid errors caused by an out-of-handle situation. Win32 handles (type HANDLE) must not be confused with RTFiles-32's file handles (type RTFHANDLE or int). Win32 handles reference objects indirectly, while RTFiles-32 handles reference them directly. Consequently, Win32 handles can be duplicated with function DuplicateHandle; the associated file is closed only after all handles have been closed. In contrast, RTFiles-32 file handles cannot be duplicated; they can only be copied, which does not create a new handle. Any call to RTFClose will immediately close the file. RTTarget-32 Flag RT_CLOSE_FIND_HANDLESRTTarget-32 has a flag to work around a problem in some C/C++ run-time systems or older programs ported from DOS. The Win32 API functions to search for files are FindFirstFile, FindNextFile, and FindClose. FindFirstFile returns a handle which can be used in subsequent FindNextFile calls. This handle must be closed with FindClose to avoid a Win32 handle leak. However, under DOS, the corresponding DOS functions do not require closing such a handle. For this reason, some older programs never close find handles. RTTarget-32 allocates a Win32 handle in each FindFirstFile call and RTFiles-32 allocates a file handle in each call to RTFFindFirst (which is called by FindFirstFile). Thus, programs that do not close find handles will quickly exhaust all available Win32 and RTFiles-32 handles. To work around this problem, RTTarget-32 can be instructed to automatically close find handles once no more files are found in FindNextFile. To use this feature, call RTSetFlags(RT_CLOSE_FIND_HANDLES, 1); during the startup phase of the program. If this feature is used, programs which do close the find handle after no more files are found will receive an error from FindClose since the handle has been closed already. However, this should normally not cause any problems. You should use RT_CLOSE_FIND_HANDLES only to support software with this bug which cannot be modified. Well-behaved programs should always close find handles (either Win32 handles with FindClose or the RTFiles-32 handle with RTFFindClose, if RTFiles-32's native API is used). ANSI C Run-Time System Functions
|