home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / devnews / vol2 / sample1 / samp1.c
Encoding:
Text File  |  1993-10-22  |  1.9 KB  |  101 lines

  1.  
  2. Listing 4/Keenleyside
  3.  
  4. This listing shows you how to write a DLL entry point function
  5. using the features of C Set ++.
  6.  
  7.  
  8. /* From DLLENTRY.C */
  9. #pragma strings(readonly)
  10.  
  11. #define INCL_DOSFILEMGR
  12. #define INCL_DOSMODULEMGR
  13. #include <os2.h>
  14. #include <string.h>
  15.  
  16. int _dllentry = 1;  /* just in case an object is compiled with /Ge-
  17. */
  18. char name[CCHMAXPATH];
  19.  
  20. #pragma entry(entry)
  21. unsigned long _System entry(unsigned long hModule, unsigned long
  22. ulFlag)
  23. {
  24.    APIRET rc;
  25.    unsigned long ulBytesWritten;
  26.  
  27.    rc = DosQueryModuleName(hModule, CCHMAXPATH, name);
  28.  
  29.    if (!rc)
  30.    {
  31.       if (ulFlag == 0)
  32.       {
  33.          rc = DosWrite(1, name, strlen(name), &ulBytesWritten);
  34.          rc = DosWrite(1, " initialized.\r\n", 15,
  35. &ulBytesWritten);
  36.       }
  37.       else
  38.       {
  39.          rc = DosWrite(1, name, strlen(name), &ulBytesWritten);
  40.          rc = DosWrite(1, " terminated.\r\n", 14, &ulBytesWritten);
  41.       }
  42.    }
  43.  
  44.    return !rc;   /* non-zero means DLL init/term was successful */
  45. }
  46.  
  47. void hello(void)
  48. {
  49.    unsigned long ulBytesWritten;
  50.  
  51.    DosWrite(1, "Hello there\r\n", 13, &ulBytesWritten);
  52.  
  53.    return;
  54. }
  55.  
  56. /* From SIMPLE.DEF */
  57. LIBRARY SIMPLE INITINSTANCE TERMINSTANCE
  58.  
  59. EXPORTS
  60.    hello
  61.  
  62. /* From RUNTIME.C */
  63. #pragma strings(readonly)
  64.  
  65. #define INCL_DOSMODULEMGR
  66. #define INCL_DOSPROCESS
  67. #include <os2.h>
  68.  
  69. char pszErrorBuf[CCHMAXPATH];
  70.  
  71. void hello(void);
  72.  
  73. int main(void)
  74. {
  75.    APIRET rc;
  76.    HMODULE hDLL;
  77.    PFN pHello;
  78.  
  79.    rc = DosLoadModule(pszErrorBuf, CCHMAXPATH, "SIMPLE", &hDLL);
  80.  
  81.    if (!rc)
  82.    {
  83.       rc = DosQueryProcAddr(hDLL, 0, "hello", &pHello);
  84.  
  85.       if (!rc)
  86.          pHello();
  87.  
  88.       rc = DosFreeModule(hDLL);
  89.    }
  90.  
  91.    return rc;
  92. }
  93.  
  94. /* From BUILD.CMD */
  95. /* Build a simple DLL that shows how the DLL entry point function
  96. works. */
  97. 'ICC /C /Rn /O+ DLLENTRY.C'
  98. 'ICC /Rn /Ge- /FeSIMPLE.DLL DLLENTRY SIMPLE.DEF'
  99. 'ICC /Rn /O+ RUNTIME.C'
  100.  
  101.