Home |
RTTarget-32 Programming Manual Running Win32 Programs without Win32 Running a Program on the Target Win32 Date and Time Management Win32 Thread Local Storage (TLS) Win32 API Function Cross Reference Adding other Win32 Functions Alternate Heap Manager RTTHeap Compiling and Linking with On Time RTOS-32 |
Adding other Win32 FunctionsIf a program requires a Win32 function (a function defined in one of Windows' system DLLs), and the function is not provided by Rtt32.lib or Rtt32dll.dll, the function must be supplied by your program. The following steps are required:
Example:Suppose you need the function CharUpperA, which is not included in RTTarget-32's library. The following source code could be used to implement it: #define _USER32_ // required by Microsoft C #define _KERNEL32_ // to prevent importing this function #include <windows.h> WINUSERAPI LPSTR WINAPI CharUpperA(LPSTR lpsz) { LPSTR p = lpsz; while (*p) { if (*p >= 'a' && *p <= 'z') *p -= 'a' - 'A'; p++; } return lpsz; } This file should be compiled and linked with your program. For Microsoft C, an assembler call stub is also required: .386 EXTRN _CharUpperA@4:near PUBLIC __imp__CharUpperA@4 PUBLIC _CharUpperA _TEXT SEGMENT DWORD USE32 PUBLIC 'CODE' ASSUME CS:_TEXT, DS:_TEXT __imp__CharUpperA@4 DD offset _CharUpperA@4 _CharUpperA: JMP _CharUpperA@4 _TEXT ENDS END The numeric value following the at sign (@) represents the number of bytes the function expects as parameters. The value is decimal and is usually four times the number of parameters. Function CharUpperA requires just one parameter, so 4 bytes are pushed onto the stack. The call stub must be assembled and linked to the program. As an alternative to a call stub, it is also possible to use RTLoc's Link command. In this case, the import table's call stub is used. Win32 API Function Cross Reference
|