| 1 | /* $Id: dll-c.c,v 1.1 2002-05-16 11:37:06 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * Test DLL.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 2002 knut st. osmundsen (bird@anduin.net)
|
|---|
| 6 | *
|
|---|
| 7 | * GPL
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /*******************************************************************************
|
|---|
| 12 | * Defined Constants And Macros *
|
|---|
| 13 | *******************************************************************************/
|
|---|
| 14 | #ifdef DEBUG
|
|---|
| 15 | #define _STR "\"DEBUG\" "
|
|---|
| 16 | #else
|
|---|
| 17 | #define _STR ""
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #ifdef __cplusplus
|
|---|
| 21 | extern "C" {
|
|---|
| 22 | #endif
|
|---|
| 23 |
|
|---|
| 24 | #if (defined(__IBMCPP__) || defined(__IBMC__))
|
|---|
| 25 |
|
|---|
| 26 | #define DLLENTRYPOINT_CCONV _System
|
|---|
| 27 | #define DLLENTRYPOINT_NAME _DLL_InitTerm
|
|---|
| 28 |
|
|---|
| 29 | #if (__IBMCPP__ == 300) || (__IBMC__ == 300)
|
|---|
| 30 | void _Optlink __ctordtorInit( void );
|
|---|
| 31 | #define ctordtorInit() __ctordtorInit()
|
|---|
| 32 |
|
|---|
| 33 | void _Optlink __ctordtorTerm( void );
|
|---|
| 34 | #define ctordtorTerm() __ctordtorTerm()
|
|---|
| 35 |
|
|---|
| 36 | #elif (__IBMCPP__ == 360) || (__IBMC__ == 360)
|
|---|
| 37 | void _Optlink __ctordtorInit( int flag );
|
|---|
| 38 | #define ctordtorInit() __ctordtorInit(0)
|
|---|
| 39 |
|
|---|
| 40 | void _Optlink __ctordtorTerm( int flag );
|
|---|
| 41 | #define ctordtorTerm() __ctordtorTerm(0)
|
|---|
| 42 |
|
|---|
| 43 | #else
|
|---|
| 44 | #error "Unknown compiler!"
|
|---|
| 45 | #endif
|
|---|
| 46 |
|
|---|
| 47 | int _Optlink _CRT_init(void);
|
|---|
| 48 | void _Optlink _CRT_term(void);
|
|---|
| 49 |
|
|---|
| 50 | #elif defined(__WATCOMC__)
|
|---|
| 51 |
|
|---|
| 52 | #define DLLENTRYPOINT_CCONV _syscall
|
|---|
| 53 | #define DLLENTRYPOINT_NAME LibMain
|
|---|
| 54 |
|
|---|
| 55 | #define ctordtorInit() ((void)0)
|
|---|
| 56 | #define ctordtorTerm() ((void)0)
|
|---|
| 57 |
|
|---|
| 58 | #define _CRT_init() ((void)0)
|
|---|
| 59 | #define _CRT_term() ((void)0)
|
|---|
| 60 |
|
|---|
| 61 | #endif
|
|---|
| 62 |
|
|---|
| 63 | #ifdef __cplusplus
|
|---|
| 64 | }
|
|---|
| 65 | #endif
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | /*******************************************************************************
|
|---|
| 71 | * Header Files *
|
|---|
| 72 | *******************************************************************************/
|
|---|
| 73 | #include <stdio.h>
|
|---|
| 74 | #include <math.h>
|
|---|
| 75 |
|
|---|
| 76 | #ifdef OS2
|
|---|
| 77 | #include <os2.h>
|
|---|
| 78 | #define OSCALL APIENTRY
|
|---|
| 79 | #endif
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | * Testprogram.
|
|---|
| 83 | * @returns 0 on success.
|
|---|
| 84 | */
|
|---|
| 85 | int OSCALL FOO42(void)
|
|---|
| 86 | {
|
|---|
| 87 | long double lrd = asin(cos(0));
|
|---|
| 88 | lrd = lrd;
|
|---|
| 89 |
|
|---|
| 90 | #if !defined(DLLENTRYPOINT_NAME)
|
|---|
| 91 | puts("DLLInit");
|
|---|
| 92 | #endif
|
|---|
| 93 |
|
|---|
| 94 | #ifdef __cplusplus
|
|---|
| 95 | puts("Hello \"C++\" "_STR"World!");
|
|---|
| 96 | #else
|
|---|
| 97 | puts("Hello \"C\" "_STR"World!");
|
|---|
| 98 | #endif
|
|---|
| 99 |
|
|---|
| 100 | /*
|
|---|
| 101 | * Define assertions.
|
|---|
| 102 | */
|
|---|
| 103 | #ifdef __32BIT__
|
|---|
| 104 | # ifdef __16BIT__
|
|---|
| 105 | puts("error: __16BIT__ && __32BIT__ is defined!");
|
|---|
| 106 | # else
|
|---|
| 107 | puts("__32BIT__");
|
|---|
| 108 | # endif
|
|---|
| 109 | #else
|
|---|
| 110 | # ifdef __16BIT__
|
|---|
| 111 | puts("__16BIT__");
|
|---|
| 112 | # else
|
|---|
| 113 | puts("error: __16BIT__ nor __32BIT__ is defined!");
|
|---|
| 114 | # endif
|
|---|
| 115 |
|
|---|
| 116 | #endif
|
|---|
| 117 |
|
|---|
| 118 | #if !defined(OS2) && !defined(WIN32) && !defined(LINUX)
|
|---|
| 119 | puts("error: OS is not defined!");
|
|---|
| 120 | #endif
|
|---|
| 121 |
|
|---|
| 122 | return 0;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | int OSCALL FOONAME(void)
|
|---|
| 127 | {
|
|---|
| 128 | puts("FOOName");
|
|---|
| 129 | #if !defined(DLLENTRYPOINT_NAME)
|
|---|
| 130 | puts("DLLTerm");
|
|---|
| 131 | #endif
|
|---|
| 132 | return 0;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | #if defined(DLLENTRYPOINT_NAME) && defined(OS2)
|
|---|
| 137 | int DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(int hmod, int fFlags)
|
|---|
| 138 | {
|
|---|
| 139 | switch (fFlags)
|
|---|
| 140 | {
|
|---|
| 141 | case 0:
|
|---|
| 142 | {
|
|---|
| 143 | ctordtorInit();
|
|---|
| 144 | _CRT_init();
|
|---|
| 145 | puts("DLLInit");
|
|---|
| 146 | break;
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | case 1:
|
|---|
| 150 | {
|
|---|
| 151 | #ifdef __WATCOMC__
|
|---|
| 152 | /* probably already terminated by now. */
|
|---|
| 153 | #ifdef __16BIT__
|
|---|
| 154 | USHORT Dummy;
|
|---|
| 155 | #else
|
|---|
| 156 | ULONG Dummy;
|
|---|
| 157 | #endif
|
|---|
| 158 | DosWrite((HFILE)1 /*HF_STDOUT*/, "DLLTerm\r\n", 9, &Dummy);
|
|---|
| 159 | #else
|
|---|
| 160 | puts("DLLTerm");
|
|---|
| 161 | #endif
|
|---|
| 162 | ctordtorTerm();
|
|---|
| 163 | _CRT_term();
|
|---|
| 164 | break;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | default:
|
|---|
| 168 | return 0;
|
|---|
| 169 | }
|
|---|
| 170 | return 1;
|
|---|
| 171 | }
|
|---|
| 172 | #endif
|
|---|