Differences
This shows you the differences between two versions of the page.
| en:docs:win16:api:user:initapp [2026/02/18 02:03] – created prokushev | en:docs:win16:api:user:initapp [2026/05/04 07:26] (current) – prokushev | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| {{page> | {{page> | ||
| - | ====== | + | ====== |
| ===== Brief ===== | ===== Brief ===== | ||
| + | |||
| + | The **InitApp** function creates the application message queue and installs essential application-support routines. These include a signal procedure, version-specific resource loaders, and a divide-by-zero interrupt handler. | ||
| ===== Syntax ===== | ===== Syntax ===== | ||
| + | |||
| + | <code c> | ||
| + | BOOL WINAPI InitApp(HANDLE hInstance); | ||
| + | </ | ||
| ===== Parameters ===== | ===== Parameters ===== | ||
| + | |||
| + | * **hInstance** — Handle to the task to be initialized. This value **must** be the instance handle returned in the `DI` register by the preceding `InitTask` call. | ||
| ===== Return Code ===== | ===== Return Code ===== | ||
| + | |||
| + | Returns **nonzero** in the `AX` register if successful. If the function fails, it returns **zero**, and the application must exit immediately. | ||
| ===== Notes ===== | ===== Notes ===== | ||
| + | |||
| + | * Because this function creates the message queue, failure to call it (or calling out of sequence) will result in an application that cannot receive messages. | ||
| ===== Example Code ===== | ===== Example Code ===== | ||
| ==== C Binding ==== | ==== C Binding ==== | ||
| + | <code c> | ||
| + | /* Declaration of InitApp (often not included in windows.h) */ | ||
| + | extern WINAPI InitApp(HANDLE hInstance); | ||
| + | |||
| + | int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, | ||
| + | LPSTR lpCmdLine, int nCmdShow) | ||
| + | { | ||
| + | /* InitApp is typically called in the startup code before WinMain. | ||
| + | If you are writing custom startup code, call it as shown: */ | ||
| + | if (!InitApp(hInstance)) | ||
| + | { | ||
| + | /* Critical error: message queue could not be created */ | ||
| + | return 1; | ||
| + | } | ||
| + | |||
| + | /* ... application code ... */ | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| ==== MASM Binding ==== | ==== MASM Binding ==== | ||
| + | <code asm> | ||
| + | ; Standard startup fragment (after InitTask and WaitEvent) | ||
| + | externFP | ||
| + | |||
| + | push di ; hInstance from InitTask (DI register) | ||
| + | call far InitApp | ||
| + | or ax, ax ; test return value | ||
| + | jz noinit | ||
| + | |||
| + | ; ... proceed to call WinMain ... | ||
| + | |||
| + | noinit: | ||
| + | mov al, 0FFh ; return error code | ||
| + | mov ah, 4Ch | ||
| + | int 21h | ||
| + | </ | ||
| ===== See also ===== | ===== See also ===== | ||
| - | {{page>en:templates:win16}} | + | * [[en:docs:win16: |
| + | * [[en: | ||
| + | {{page> | ||




