home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05041a < prev    next >
Text File  |  1992-02-19  |  4KB  |  158 lines

  1. ' DLL parameter test program
  2. ' Copyright (c) 1992, by Desaware
  3. ' All rights reserved
  4. '
  5. '
  6. ' This program is used to test the dllparam.dll dynamic
  7. ' link library.
  8.  
  9. ' Passing singles by value and returning singles
  10. Sub TestSingleByval_Click ()
  11.     f! = ReceivesSingle(1.59)
  12. End Sub
  13.  
  14. ' Passing longs by value and returning longs
  15. Sub TestLongByval_Click ()
  16.     y& = ReceivesLong(6)
  17. End Sub
  18.  
  19. ' Passing doubles by value and returning doubles
  20. Sub TestDoubleByval_Click ()
  21.     d# = ReceivesDouble(3.145)
  22. End Sub
  23.  
  24. ' Passing integers by reference
  25. Sub TestIntByref_Click ()
  26.     x% = 5
  27.     Add5ToInteger x%
  28.     MsgBox Str$(x%), 0, "Add5ToInteger"
  29. End Sub
  30.  
  31. ' Passing longs by reference
  32. Sub TestLongByref_Click ()
  33.     y& = 6
  34.     Add5ToLong y&
  35.     MsgBox Str$(y&), 0, "Add5ToLong"
  36.  
  37. End Sub
  38.  
  39. ' Passing singles by reference
  40. Sub TestSingleByref_Click ()
  41.     f! = 1.59
  42.     Add5ToSingle f!
  43.     MsgBox Str$(f!), 0, "Add5ToSingle"
  44.  
  45. End Sub
  46.  
  47. ' Passing doubles by reference
  48. Sub TestDoubleByref_Click ()
  49.     d# = 3.145
  50.     Add5ToDouble d#
  51.     MsgBox Str$(d#), 0, "Add5ToDouble"
  52.  
  53. End Sub
  54.  
  55. ' Passing strings (null terminated)
  56. ' Always by reference
  57. Sub TestString_Click ()
  58.     ReceivesString "Hello"
  59. End Sub
  60.  
  61. ' Passing and modifying strings (null terminated)
  62. ' Always by reference
  63. Sub TestStringChange_Click ()
  64.     ' Null terminated string is passed to the routine
  65.     ' x$ must be preinitialized to the maximum length.
  66.     ' The DLL may change the contents of the string, but
  67.     ' must never go past the null terminator
  68.     x$ = "Hello"
  69.     ChangesString x$
  70.     MsgBox x$, 0, "ChangesString"
  71. End Sub
  72.  
  73. ' Passing controls and forms as parameters
  74. Sub TestControl_Click ()
  75.     hctl% = GetControlHwnd(TestControl)
  76.     hfrm% = GetFormHwnd(dllparam)
  77.     MsgBox "This control hwnd is " + Str$(hctl%) + ", the form hwnd is " + Str$(hfrm%), 0, "Get Hwnds"
  78. End Sub
  79.  
  80. ' Passing Visual Basic strings
  81. Sub TestVBString_Click ()
  82.     ReceivesVBString "String to DLL"
  83. End Sub
  84.  
  85. ' Passing and modifying Visual Basic strings
  86. ' Note - no length restrictions apply
  87. Sub TestVBStringChange_Click ()
  88.     a$ = "Short"
  89.     ChangesVBString a$
  90.     MsgBox a$, 0, "ChangesVBString"
  91. End Sub
  92.  
  93. ' A DLL function returning a Visual Basic String
  94. Sub ReturnVBString_Click ()
  95.     a$ = ReturnsVBString()
  96.     MsgBox a$, 0, "ReturnsVBString"
  97. End Sub
  98.  
  99. ' Passing user defined types
  100. ' Always by reference
  101. Sub TestUserType_Click ()
  102.     Dim u As usertype
  103.     u.a = 1
  104.     u.b = 2
  105.     u.c = 3
  106.     u.d = 4
  107.     ' Note - this is call by reference, the DLL can change
  108.     ' the value of u
  109.     ReceivesUserType u
  110. End Sub
  111.  
  112. ' Passing currency by value and returning currency
  113. Sub TestCurrencyByval_Click ()
  114.     Dim c@
  115.     c = 1.2345
  116.     c = ReceivesCurrency(c)
  117. End Sub
  118.  
  119. ' Passing currency by reference
  120. Sub TestCurrencyByref_Click ()
  121.     Dim c@
  122.     c@ = 1.23
  123.     AddPennyToCurrency c@
  124.     MsgBox Str$(c@), 0, "AddPennyToCurrency"
  125. End Sub
  126.  
  127. ' Passing integers by value and returning integers
  128. Sub TestIntByval_Click ()
  129.     x% = ReceivesInteger(5)
  130. End Sub
  131.  
  132. ' This is a test of passing a pointer to a numeric array
  133. ' Note the unique DLL call
  134. '
  135. Sub ReceivesIntArray_Click ()
  136.     ReDim x(4) As Integer
  137.     x(0) = 1
  138.     x(1) = 3
  139.     x(2) = 9
  140.     x(3) = 81
  141.     ' Pass a pointer to the first element of the array.
  142.     ' The DLL has no way of knowing how long the array is
  143.     ' unless you define a length parameter for the function.
  144.     ReceivesIntArray x(0)
  145. End Sub
  146.  
  147. '   Show how to access strings inside user defined types
  148. Sub TestAddUserString_Click ()
  149.     Dim u As usertype
  150.     ' Note - this is call by reference, the DLL can change
  151.     ' the value of u
  152.     u.s = "orignal string"
  153.     AddUserString u
  154.     MsgBox u.s, 0, "String in usertype changed"
  155.  
  156. End Sub
  157.  
  158.