| Last change
 on this file since 22056 was             21999, checked in by dmik, 14 years ago | 
        
          | 
kernel32: Make SEH work in OS/2 context.
 
See #82 for details.
 | 
        
          | File size:
            1.6 KB | 
      
      
| Line |  | 
|---|
| 1 | #include <stdio.h> | 
|---|
| 2 | #include <windows.h> | 
|---|
| 3 | #include <excpt.h> | 
|---|
| 4 |  | 
|---|
| 5 | #ifndef _MSC_VER | 
|---|
| 6 |  | 
|---|
| 7 | #include <odinlx.h> | 
|---|
| 8 |  | 
|---|
| 9 | int _main(); | 
|---|
| 10 | int _argc; | 
|---|
| 11 | char **_argv; | 
|---|
| 12 |  | 
|---|
| 13 | int WIN32API WinMain(HANDLE hInstance, | 
|---|
| 14 | HANDLE hPrevInstance, | 
|---|
| 15 | LPSTR  lpCmdLine, | 
|---|
| 16 | int    nCmdShow) | 
|---|
| 17 | { | 
|---|
| 18 | return _main(_argc, _argv); | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 | int main(int argc, char **argv) | 
|---|
| 22 | { | 
|---|
| 23 | _argc = argc; | 
|---|
| 24 | _argv = argv; | 
|---|
| 25 | #ifdef ODIN_FORCE_WIN32_TIB | 
|---|
| 26 | ForceWin32TIB(); | 
|---|
| 27 | #endif | 
|---|
| 28 | RegisterLxExe(WinMain, NULL); | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | #else | 
|---|
| 32 | #define _main main | 
|---|
| 33 | #endif | 
|---|
| 34 |  | 
|---|
| 35 | void throw_EXCEPTION_INT_DIVIDE_BY_ZERO() | 
|---|
| 36 | { | 
|---|
| 37 | printf("Throwing EXCEPTION_INT_DIVIDE_BY_ZERO...\n"); | 
|---|
| 38 | int x = 0; | 
|---|
| 39 | volatile int y = 4 / x; | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | int _main(int argc, char **argv) | 
|---|
| 43 | { | 
|---|
| 44 | int code = argc > 1 ? atoi(argv[1]) : 0; | 
|---|
| 45 |  | 
|---|
| 46 | __try | 
|---|
| 47 | { | 
|---|
| 48 | switch(code) | 
|---|
| 49 | { | 
|---|
| 50 | case 1: | 
|---|
| 51 | { | 
|---|
| 52 | throw_EXCEPTION_INT_DIVIDE_BY_ZERO(); | 
|---|
| 53 | printf("FAILED: Exception was not thrown!\n"); | 
|---|
| 54 | return 1; | 
|---|
| 55 | } | 
|---|
| 56 | case 2: | 
|---|
| 57 | { | 
|---|
| 58 | printf("Doing __leave...\n"); | 
|---|
| 59 | __leave; | 
|---|
| 60 | printf("FAILED: __leave didn't work!\n"); | 
|---|
| 61 | return 1; | 
|---|
| 62 | } | 
|---|
| 63 | case 3: | 
|---|
| 64 | default: | 
|---|
| 65 | { | 
|---|
| 66 | printf("Not causing exceptions, not doing __leave...\n"); | 
|---|
| 67 | break; | 
|---|
| 68 | } | 
|---|
| 69 | } | 
|---|
| 70 | } | 
|---|
| 71 | __finally | 
|---|
| 72 | { | 
|---|
| 73 | // handle exception | 
|---|
| 74 | printf("Finally block executed.\n"); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | printf("Return.\n"); | 
|---|
| 78 |  | 
|---|
| 79 | return 0; | 
|---|
| 80 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.