| 1 | /* $Id: dll-prog-c.c,v 1.1 2002-05-16 11:37:06 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * DLL Test program. | 
|---|
| 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 |  | 
|---|
| 15 |  | 
|---|
| 16 | /******************************************************************************* | 
|---|
| 17 | *   Header Files                                                               * | 
|---|
| 18 | *******************************************************************************/ | 
|---|
| 19 | #include <stdio.h> | 
|---|
| 20 | #ifdef OS2 | 
|---|
| 21 | #define INCL_DOS | 
|---|
| 22 | #include <os2.h> | 
|---|
| 23 | #endif | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 | /** | 
|---|
| 27 | * Testprogram. | 
|---|
| 28 | * @returns 0 on success. | 
|---|
| 29 | */ | 
|---|
| 30 | int main(int argc, char **argv) | 
|---|
| 31 | { | 
|---|
| 32 | #ifdef OS2 | 
|---|
| 33 | PFN         pfnFoo42; | 
|---|
| 34 | PFN         pfnFooName; | 
|---|
| 35 | int         rc; | 
|---|
| 36 | HMODULE     hmod; | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | if (argc != 2) | 
|---|
| 40 | { | 
|---|
| 41 | printf("Syntax error!\nsyntax: %s <dllname>\n", argv[0]); | 
|---|
| 42 | return 16; | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 |  | 
|---|
| 46 | #ifdef OS2 | 
|---|
| 47 | rc = DosLoadModule(NULL, 0, argv[1], &hmod); | 
|---|
| 48 | if (rc) | 
|---|
| 49 | { | 
|---|
| 50 | printf("Failed to load module '%s'. rc=%d\n", argv[1], rc); | 
|---|
| 51 | return 16; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | #ifdef __16BIT__ | 
|---|
| 55 | rc = DosGetProcAddr(hmod, "#42", &pfnFoo42); | 
|---|
| 56 | #else | 
|---|
| 57 | rc = DosQueryProcAddr(hmod, 42, NULL, &pfnFoo42); | 
|---|
| 58 | #endif | 
|---|
| 59 | if (rc) | 
|---|
| 60 | { | 
|---|
| 61 | printf("Failed to get function at ordinal 42. rc=%d\n", rc); | 
|---|
| 62 | return 16; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 | #ifdef __16BIT__ | 
|---|
| 66 | rc = DosGetProcAddr(hmod, "FOONAME", &pfnFooName); | 
|---|
| 67 | #else | 
|---|
| 68 | rc = DosQueryProcAddr(hmod, 0, "FOONAME", &pfnFooName); | 
|---|
| 69 | #endif | 
|---|
| 70 | if (rc) | 
|---|
| 71 | { | 
|---|
| 72 | printf("Failed to get function at ordinal 42. rc=%d\n", rc); | 
|---|
| 73 | return 16; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | #endif | 
|---|
| 77 |  | 
|---|
| 78 | /* | 
|---|
| 79 | * Call the functions. | 
|---|
| 80 | */ | 
|---|
| 81 | (*pfnFoo42)(); | 
|---|
| 82 | (*pfnFooName)(); | 
|---|
| 83 |  | 
|---|
| 84 | return 0; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|