home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / e_macros / dynatest.e < prev    next >
Encoding:
Text File  |  1991-06-11  |  21.0 KB  |  329 lines

  1. /**
  2. *
  3. * name          dynatest - test the dynamic link function of OS/2
  4. * author        Ralph Yozzo
  5. *
  6. * usage         dynatest
  7. *
  8. * compiler      ET
  9. *
  10. * command
  11. * used to       et e
  12. * compile
  13. *
  14. * description   This program shows the usage of OS/2 dynamic linkage.
  15. *     2.3.8.1  Dynamic Linking
  16. *     Dynamic linking is the delayed binding of application program external
  17. *     references to subroutines.  There are two forms of dynamic linking --
  18. *     load time and run time.
  19. *
  20. *     In load time dynamic linking, a program calls a dynamically linked
  21. *     routine just as it would any external routine.  When the program is
  22. *     assembled or compiled, a standard external reference is generated.  At
  23. *     link time, the programmer specifies one or more libraries which
  24. *     contain routines to satisfy external references.  External routines to
  25. *     be dynamically linked contain special definition records in the
  26. *     library.  A definition record tells the linker that the routine in
  27. *     question is to be dynamically linked and provides the linker with a
  28. *     dynamic link module name and entry name.  The module name is the name
  29. *     of a special executable file with the filename extension of .DLL which
  30. *     contains dynamic link entry points.  The linker stores module
  31. *     name/entry name pairs describing the dynamic link routines in the
  32. *     executable file created for the program.  When the calling program is
  33. *     run, OS/2 loads the dynamic link routines from the modules specified
  34. *     and links the calling program to the called routines.  (os/2 technical
  35. *     reference)
  36. *
  37. **/
  38. defc dynatest=
  39.    result=dynalink('DOSCALLS',      /* dynamic link library name       */
  40.                    '#50',           /* ordinal value for DOSBEEP       */
  41.                    \255\0\255\0)    /* stack string                    */
  42.  
  43.    call getkey()                    /*                                 */
  44.  
  45.    string='hello'                   /* input string                    */
  46.  
  47.    result=dynalink('VIOCALLS',      /* dynamic link library name       */
  48.                    'VIOWRTTTY',     /* Video Input Output WRiTe TeleTYpe */
  49.                    selector(string)|| /* string selector               */
  50.                    offset(string)|| /* string offset                   */
  51.                    atoi(length(string))|| /* length of string          */
  52.                    atoi(0))         /* Vio Handle */
  53.  
  54.  
  55.    call getkey()
  56.    string =  '?????'                /* result buffer                   */
  57.    result=dynalink('DOSCALLS',      /* dynamic link library name       */
  58.                    '#127',          /* ordinal value for DOSMEMAVAIL   */
  59.                    selector(string)|| /* string selector               */
  60.                    offset(string))    /* string offset                 */
  61.    sayerror 'memavail = ' string 'itoa(hex) = ' itoa(string,16)
  62.    call getkey()
  63.    sayerror 'memavail = ' string 'memavail(hex) = ' hex_to_string(string)
  64.    call getkey()
  65.  
  66. /*********************************************************************/
  67. /* Do not do the following as it will cause a protection violation.  */
  68. /* The number of parameters placed on the stack is wrong.            */
  69. /*********************************************************************/
  70. ;  string =  '?????'
  71. ;  result=dynalink('DOSCALLS',
  72. ;                  '#127',
  73. ;                  selector(string)||
  74. ;                  offset(string)||
  75. ;                  atoi(0))       /* WRONG!  Too many parameters stacked */
  76. ;  sayerror 'memavail = ' string 'memavail(hex) = ' hex_to_string(string)
  77.  
  78.    string =  atoi(80) || substr('',1,80)  /* create input strings for  */
  79.    stringlen = substr('',1,4)             /* DOSQCURDIR                */
  80.    result=dynalink('DOSCALLS',
  81.                    '#71',
  82.                    atoi(0)||               /* Drive number - 1=A, etc */
  83.                    selector(string)||      /* Directory path buffer */
  84.                    offset(string)||
  85.                    selector(stringlen)||   /* Directory path buffer length */
  86.                    offset(stringlen))
  87.    sayerror  'len = ' hex_to_string(stringlen) 'current dir = ' string
  88.  
  89. defc dynaparm=
  90.    parse value arg(1) with module procedure stack
  91.    result=dynalink(module,procedure,stack)
  92.  
  93. defc atoitest=
  94.    sayerror 'atoi = ' hex_to_string(atoi(arg(1)))
  95.  
  96. defc atoltest=
  97.    sayerror 'atol = ' hex_to_string(atol(arg(1)))
  98.  
  99. defc seltest=
  100.    universal dynalinkvariable
  101.    sayerror 'selector = ' hex_to_string(selector(dynalinkvariable))
  102.  
  103. defc offtest=
  104.    universal dynalinkvariable
  105.    sayerror 'offset = ' hex_to_string(offset(dynalinkvariable))
  106.  
  107.  
  108. defproc hex_to_string(string)
  109.    line = ''
  110.    for i = 1 to length(string)
  111.       line= line || hex(substr(string,i,1)) || ' '
  112.    endfor
  113.    return line
  114.  
  115. defc itoause=
  116.    sayerror 'itoa = ' itoa(atoi(arg(1)),10)
  117.  
  118. defc ltoause=
  119.    sayerror 'ltoa = ' ltoa(atol(arg(1)),10)
  120.  
  121. defc itoatest=
  122.    sayerror 'itoa = ' itoa(arg(1),10)
  123.  
  124. defc ltoatest=
  125.    sayerror 'ltoa = ' ltoa(arg(1),10)
  126.  
  127. defproc beep(pitch,duration)
  128.    result=dynalink('DOSCALLS',      /* dynamic link library name       */
  129.                    '#50',           /* ordinal value for DOSBEEP       */
  130.                    atoi(pitch)||    /* Hertz (25H-7FFFH) */
  131.                    atoi(duration))  /* Length of sound  in ms */
  132.  
  133. defc beeptest=
  134.    parse value arg(1) with pitch duration
  135.    call beep(pitch,duration)
  136.  
  137. defc testcolor
  138.    sayerror 'color_mode()='color_mode()'.'
  139.  
  140. -- Returns 1 if color, 0 if mono.
  141. defproc color_mode()
  142.    if machine()='OS2PROTECT' then
  143.       ModeData=atoi(12)||'tCccrrhhvv'  /* data structure, length first    */
  144.       result=dynalink('VIOCALLS',            /* dynamic link library name */
  145.                       'VIOGETMODE',          /* Get display mode          */
  146.                       selector(ModeData) ||  /* string selector           */
  147.                       offset(ModeData)   ||  /* string offset             */
  148.                       atoi(0))               /* Vio Handle                */
  149.       -- Bit 1 is 1 if color.
  150.       type = itoa(substr(ModeData,3,1),10)  -- single-byte number
  151.       if 2*(type%2) = type then
  152.          return 0
  153.       endif
  154.       return 1
  155.    else
  156.       result=int86x(16,15*256,0)
  157.       parse value result with ax .
  158.       al = ax // 256
  159.       if al=0 or al=2 or al=7 then
  160.          return 0
  161.       endif
  162.       return 1
  163.    endif
  164.  
  165. defc windowtest=
  166.    parse value arg(1) with writerow writecolumn string
  167.    sayerror 'rc=' window(string,writerow,writecolumn,0,0,0,0)
  168.  
  169. defproc window(string,writerow,writecolumn,row,column,width,depth)
  170.    return dynalink('VIOCALLS',            /* dynamic link library name */
  171.                    'VIOWRTCHARSTR',       /* video input/output call   */
  172.                    selector(string)   ||  /* string selector           */
  173.                    offset(string)     ||  /* string offset             */
  174.                    atoi(length(string)) ||/* length of string          */
  175.                    atoi(writerow)     ||  /* write at row position     */
  176.                    atoi(writecolumn)  ||  /* write at col position     */
  177.                    atoi(0))               /* reserved                  */
  178.  
  179. defc windowattr=
  180.    parse value arg(1) with writerow writecolumn attribute string
  181.    sayerror 'rc=' windowattr(string,writerow,writecolumn,0,0,0,0,attribute) rc
  182.  
  183. defc dynamic=
  184.    parse value arg(1) with attribute writerow
  185.    if attribute = '' then
  186.       attribute = 79
  187.    endif
  188.    if writerow = '' then
  189.       writerow  = 1
  190.    endif
  191.    swriterow=writerow
  192.    call windowattr('  Creating a program which calls a dynamic link routine   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  193.    call windowattr('                                                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  194.    call windowattr('  TEST.ASM                                                ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  195.    call windowattr('                                                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  196.    call windowattr('┌────────────────┐                      ┌────────────────┐',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  197.    call windowattr('│extern RUNIT:far│                      │extern RUNIT:far│',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  198.    call windowattr('│     .          │    ╔═══════════╗     ├────────────────┤',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  199.    call windowattr('│     .          │    ║  OS/2     ║     │  ┌─────────┐   │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  200.    call windowattr('│                ╞═══>║ Assembler ╠════>│  │ Code    │   │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  201.    call windowattr('│  call RUNIT    │    ║           ║     │  └─────────┘   │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  202.    call windowattr('│                │    ╚═══════════╝     │  ┌─────────┐   │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  203.    call windowattr('│     .          │                      │  │ Data    │   │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  204.    call windowattr('│     .          │                      │  └─────────┘   │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  205.    call windowattr('│                │                      │                │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  206.    call windowattr('└────────────────┘                      └────────────────┘',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  207.    call getkey()
  208.    writerow=swriterow
  209.  
  210.    call windowattr('                                                ║         ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  211.    call windowattr('  OS2SUBS.LIB                                   ║         ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  212.    call windowattr('┌───────┬────────┐                              ║         ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  213.    call windowattr('│SORT   │ 0089   │    ╔═══════════╗             ║         ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  214.    call windowattr('├───────┼────────┤    ║  OS/2     ║             ║         ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  215.    call windowattr('│DISPLAY│ 3710   ╞═══>║ Linker    ╠<════════════╝         ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  216.    call windowattr('├───────┼────────┤    ║           ║                       ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  217.    call windowattr('│RUNIT  │ 0123   │    ╚═════╦═════╝                       ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  218.    call windowattr('├───────┼────────┤          ║                             ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  219.    call windowattr('│ADM    │ 8778   │          ║                             ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  220.    call windowattr('└───────┴────────┘          ║                             ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  221.    call windowattr('                            V                             ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  222.    call windowattr('                                                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  223.    call windowattr('                                                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  224.    call windowattr('                                                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  225.    call windowattr('                                                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  226.    call getkey()
  227.    writerow=swriterow
  228.  
  229.    call windowattr('                     ┌────────────────┐                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  230.    call windowattr('                     │EXE Header      │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  231.    call windowattr('                     ├────────────────┤                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  232.    call windowattr(' DLR=                ├───┬───────┬────┤                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  233.    call windowattr(' Dynamic Link        │DLR│OS2SUBS│0123│                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  234.    call windowattr(' Reference Record    ├───┴───────┴────┤                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  235.    call windowattr('                     │  ┌─────────┐   │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  236.    call windowattr('                     │  │ Code    │   │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  237.    call windowattr('                     │  └─────────┘   │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  238.    call windowattr('                     │  ┌─────────┐   │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  239.    call windowattr('                     │  │ Data    │   │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  240.    call windowattr('                     │  └─────────┘   │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  241.    call windowattr('                     │                │                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  242.    call windowattr('                     └────────────────┘                   ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  243.    call getkey()
  244.    writerow=swriterow
  245.  
  246.    call windowattr('   Running a dynamic-link program                          ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  247.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  248.    call windowattr('  TEST.EXE                               OS2SUBS.DLL       ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  249.    call windowattr('┌────────────────┐                       ┌────────────────┐',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  250.    call windowattr('│EXE Header      │                       │EXE Header      │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  251.    call windowattr('├────────────────┤                       ├────────────────┤',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  252.    call windowattr('├───┬───────┬────┤                       │ OS2SUB_code    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  253.    call windowattr('│DLR│OS2SUBS│0123│                       │  ┌────────┐    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  254.    call windowattr('├───┴───────┴────┤                       │  │SORT    │    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  255.    call windowattr('│  ┌─────────┐   ╞═════╗       ╔═════════╡  ├────────┤    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  256.    call windowattr('│  │ TestCode│   │     ║       ║         │  │RUNIT   │    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  257.    call windowattr('│  └─────────┘   │     ║       ║         │  ├────────┤    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  258.    call windowattr('│  ┌─────────┐   │     ║       ║         │  │DISPLAY │    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  259.    call windowattr('│  │ TestData│   │     V       V         │  ├────────┤    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  260.    call windowattr('│  └─────────┘   │   ╔═══════════╗       │  │ADM     │    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  261.    call windowattr('│                │   ║  OS/2     ║       │  └────────┘    │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  262.    call windowattr('└────────────────┘   ║ Loader    ║       │  ┌───────────┐ │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  263.    call windowattr('                     ║           ║       │  │OS2SUB_data│ │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  264.    call windowattr('                     ╚═════╦═════╝       │  └───────────┘ │',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  265.    call windowattr('                           ║             └────────────────┘',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  266.    call windowattr('                           V                               ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  267.    call getkey()
  268.    writerow=swriterow
  269.  
  270.    call windowattr('Memory                                                     ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  271.    call windowattr('╔════════════════════════════════════════════════════════╗ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  272.    call windowattr('║  ┌───────────┐                             OS2SUB_code ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  273.    call windowattr('║ ┌┤ Test_code ├──────────────────┐          ┌────────┐  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  274.    call windowattr('║ │└───────────┘                  │          │SORT    │  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  275.    call windowattr('║ │┌───────────┐                  │          ├────────┤  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  276.    call windowattr('║ └┤ Test_data │                  └─────────>│RUNIT   │  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  277.    call windowattr('║  └───────────┘                             ├────────┤  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  278.    call windowattr('║  ┌──────────────┐                          │DISPLAY │  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  279.    call windowattr('║  │ OS2SUB_data  │<┐                        ├────────┤  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  280.    call windowattr('║  └──────────────┘ └────────────────────────┤ADM     │  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  281.    call windowattr('║                                            └────────┘  ║ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  282.    call windowattr('╚════════════════════════════════════════════════════════╝ ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  283.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  284.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  285.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  286.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  287.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  288.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  289.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  290.    call windowattr('                                                           ',writerow,5,0,0,0,0,attribute);writerow=writerow+1
  291.  
  292. defproc windowattr(string,writerow,writecolumn,row,column,width,depth,attribute)
  293.    attr=atoi(attribute)
  294.    return dynalink('VIOCALLS',            /* dynamic link library name */
  295.                    'VIOWRTCHARSTRATT',    /* video input/output call   */
  296.                    selector(string)   ||  /* string selector           */
  297.                    offset(string)     ||  /* string offset             */
  298.                    atoi(length(string)) ||/* length of string          */
  299.                    atoi(writerow)     ||  /* write at row position     */
  300.                    atoi(writecolumn)  ||  /* write at col position     */
  301.                    selector(attr)     ||  /* attribute to replicate    */
  302.                    offset(attr)       ||  /*                           */
  303.                    atoi(0))               /* reserved                  */
  304. defc lentest=
  305.    string='hello'                   /* input string                    */
  306.    sayerror 'dynalink:'||
  307.           dynalink('VIOCALL'\0,     /* dynamic link library name       */
  308.                    'VIOWRTTTY',     /* Video Input Output WRiTe TeleTYpe */
  309.                    selector(string)|| /* string selector               */
  310.                    offset(string)|| /* string offset                   */
  311.                    atoi(length(string))|| /* length of string          */
  312.                    atoi(0))         /* Vio Handle */
  313.  
  314. defc rytime=
  315.    datetime='12345678901234567890'
  316.    call dynalink('DOSCALLS',      /* dynamic link library name       */
  317.                  '#33',           /* ordinal value for DOSGETDATETIME*/
  318.                  selector(datetime)|| /* string selector               */
  319.                  offset(datetime))  /* string offset                   */
  320.    call messageNwait('datetime <' datetime '>')
  321.    call messageNwait('datetime <' hex_to_string(datetime) '>')
  322.    call messageNwait('datetime <' dec_to_string(datetime) '>')
  323.    string =  dec_to_string(datetime)
  324.    call messageNwait('string <' string '>')
  325.    parse value string with hour minute second hundred day month year0 year1 .
  326.    call messageNwait('time:' hour||':'||minute||':'||second||'.'|| hundred ||
  327.                      ' date: 'day ||'/'|| month ||'/'||year0 + 256*year1)
  328.  
  329.