home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / vbdll / vbdll.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-13  |  12.7 KB  |  439 lines

  1. VERSION 5.00
  2. Begin VB.Form dllparam 
  3.    Caption         =   "DLL parameter tester"
  4.    ClientHeight    =   4725
  5.    ClientLeft      =   1080
  6.    ClientTop       =   1515
  7.    ClientWidth     =   7365
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkMode        =   1  'Source
  18.    LinkTopic       =   "Form1"
  19.    PaletteMode     =   1  'UseZOrder
  20.    ScaleHeight     =   4725
  21.    ScaleWidth      =   7365
  22.    Begin VB.CommandButton cmdObj3 
  23.       Caption         =   "Changes Obj"
  24.       Height          =   375
  25.       Left            =   3720
  26.       TabIndex        =   25
  27.       Top             =   4140
  28.       Width           =   1695
  29.    End
  30.    Begin VB.CommandButton cmdObj2 
  31.       Caption         =   "Object2"
  32.       Height          =   375
  33.       Left            =   5520
  34.       TabIndex        =   24
  35.       Top             =   3720
  36.       Width           =   855
  37.    End
  38.    Begin VB.CommandButton cmdBytes 
  39.       Caption         =   "Bytes"
  40.       Height          =   375
  41.       Left            =   4440
  42.       TabIndex        =   23
  43.       Top             =   2160
  44.       Width           =   855
  45.    End
  46.    Begin VB.CommandButton cmdRecObj 
  47.       Caption         =   "Receives Object"
  48.       Height          =   375
  49.       Left            =   3720
  50.       TabIndex        =   22
  51.       Top             =   3720
  52.       Width           =   1695
  53.    End
  54.    Begin VB.CommandButton cmdDate 
  55.       Caption         =   "Date"
  56.       Height          =   375
  57.       Left            =   6480
  58.       TabIndex        =   21
  59.       Top             =   2160
  60.       Width           =   735
  61.    End
  62.    Begin VB.CommandButton Command3 
  63.       Caption         =   "Variant ByRef"
  64.       Height          =   375
  65.       Left            =   5520
  66.       TabIndex        =   20
  67.       Top             =   3240
  68.       Width           =   1695
  69.    End
  70.    Begin VB.CommandButton Command2 
  71.       Caption         =   "VariantByVal"
  72.       Height          =   375
  73.       Left            =   3720
  74.       TabIndex        =   19
  75.       Top             =   3240
  76.       Width           =   1695
  77.    End
  78.    Begin VB.CommandButton Command1 
  79.       Caption         =   "VBArray"
  80.       Height          =   375
  81.       Left            =   5400
  82.       TabIndex        =   18
  83.       Top             =   2160
  84.       Width           =   975
  85.    End
  86.    Begin VB.CommandButton TestIntByval 
  87.       Caption         =   "ReceivesInteger(5)"
  88.       Height          =   375
  89.       Left            =   240
  90.       TabIndex        =   0
  91.       Top             =   240
  92.       Width           =   2175
  93.    End
  94.    Begin VB.CommandButton TestIntByref 
  95.       Caption         =   "Add5To5"
  96.       Height          =   375
  97.       Left            =   2640
  98.       TabIndex        =   4
  99.       Top             =   240
  100.       Width           =   1575
  101.    End
  102.    Begin VB.CommandButton TestLongByval 
  103.       Caption         =   "ReceivesLong(6)"
  104.       Height          =   375
  105.       Left            =   240
  106.       TabIndex        =   1
  107.       Top             =   720
  108.       Width           =   2175
  109.    End
  110.    Begin VB.CommandButton TestLongByref 
  111.       Caption         =   "Add5To6"
  112.       Height          =   375
  113.       Left            =   2640
  114.       TabIndex        =   5
  115.       Top             =   720
  116.       Width           =   1575
  117.    End
  118.    Begin VB.CommandButton TestSingleByval 
  119.       Caption         =   "ReceivesSingle(1.59)"
  120.       Height          =   375
  121.       Left            =   240
  122.       TabIndex        =   2
  123.       Top             =   1200
  124.       Width           =   2175
  125.    End
  126.    Begin VB.CommandButton TestSingleByref 
  127.       Caption         =   "Add5To1.59"
  128.       Height          =   375
  129.       Left            =   2640
  130.       TabIndex        =   6
  131.       Top             =   1200
  132.       Width           =   1575
  133.    End
  134.    Begin VB.CommandButton TestCurrencyByval 
  135.       Caption         =   "ReceivesCurrency(1.2345)"
  136.       Height          =   375
  137.       Left            =   4440
  138.       TabIndex        =   14
  139.       Top             =   240
  140.       Width           =   2775
  141.    End
  142.    Begin VB.CommandButton TestDoubleByval 
  143.       Caption         =   "ReceivesDouble(3.145)"
  144.       Height          =   375
  145.       Left            =   240
  146.       TabIndex        =   3
  147.       Top             =   1680
  148.       Width           =   2175
  149.    End
  150.    Begin VB.CommandButton TestDoubleByref 
  151.       Caption         =   "Add5To3.145"
  152.       Height          =   375
  153.       Left            =   2640
  154.       TabIndex        =   7
  155.       Top             =   1680
  156.       Width           =   1575
  157.    End
  158.    Begin VB.CommandButton TestCurrencyByref 
  159.       Caption         =   "AddPennyToCurrency(1.23)"
  160.       Height          =   375
  161.       Left            =   4440
  162.       TabIndex        =   15
  163.       Top             =   720
  164.       Width           =   2775
  165.    End
  166.    Begin VB.CommandButton TestString 
  167.       Caption         =   "ReceivesString ""Hello"""
  168.       Height          =   375
  169.       Left            =   240
  170.       TabIndex        =   8
  171.       Top             =   2160
  172.       Width           =   2175
  173.    End
  174.    Begin VB.CommandButton TestStringChange 
  175.       Caption         =   "Adds'!'to""Hello"""
  176.       Height          =   375
  177.       Left            =   2640
  178.       TabIndex        =   9
  179.       Top             =   2160
  180.       Width           =   1575
  181.    End
  182.    Begin VB.CommandButton TestVBString 
  183.       Caption         =   "ReceivesVBString(""String to DLL"")"
  184.       Height          =   375
  185.       Left            =   240
  186.       TabIndex        =   10
  187.       Top             =   2760
  188.       Width           =   3375
  189.    End
  190.    Begin VB.CommandButton TestUserType 
  191.       Caption         =   "ReceivesUserType(1,2,3,4)"
  192.       Height          =   375
  193.       Left            =   4440
  194.       TabIndex        =   13
  195.       Top             =   1200
  196.       Width           =   2775
  197.    End
  198.    Begin VB.CommandButton TestVBStringChange 
  199.       Caption         =   "ChangesVBString(""Short"")"
  200.       Height          =   375
  201.       Left            =   240
  202.       TabIndex        =   11
  203.       Top             =   3240
  204.       Width           =   3375
  205.    End
  206.    Begin VB.CommandButton TestAddUserString 
  207.       Caption         =   "AddUserString"
  208.       Height          =   375
  209.       Left            =   4440
  210.       TabIndex        =   17
  211.       Top             =   1680
  212.       Width           =   1455
  213.    End
  214.    Begin VB.CommandButton ReceivesIArray 
  215.       Caption         =   "Int Array"
  216.       Height          =   375
  217.       Left            =   6000
  218.       TabIndex        =   16
  219.       Top             =   1680
  220.       Width           =   1215
  221.    End
  222.    Begin VB.CommandButton ReturnVBString 
  223.       Caption         =   "ReturnsVBString()"
  224.       Height          =   375
  225.       Left            =   240
  226.       TabIndex        =   12
  227.       Top             =   3720
  228.       Width           =   3375
  229.    End
  230. Attribute VB_Name = "dllparam"
  231. Attribute VB_GlobalNameSpace = False
  232. Attribute VB_Creatable = False
  233. Attribute VB_PredeclaredId = True
  234. Attribute VB_Exposed = False
  235. ' DLL parameter test program
  236. ' Copyright (c) 1995-1997, by Desaware
  237. ' All rights reserved
  238. ' This program is used to test the VB/DLL interface
  239. ' functions defined in APIGid32.dll
  240. Private Sub cmdBytes_Click()
  241.     Dim b As Byte
  242.     b = ReceivesBytes(65, 66)
  243.     MsgBox "Received Byte " & Chr$(b)
  244. End Sub
  245. Private Sub cmdDate_Click()
  246.     Dim d, t As Date
  247.     d = Now()
  248.     t = UsesDate(d)
  249.     MsgBox "Tommorow is " & t
  250. End Sub
  251. Private Sub cmdObj2_Click()
  252.     Dim o As Object
  253.     Set o = ReceivesObject2(cmdObj2)
  254.     MsgBox "Object caption is " & o.Caption
  255. End Sub
  256. Private Sub cmdObj3_Click()
  257.     Dim orig$, final$
  258.     Dim o As Object
  259.     Set o = cmdObj3
  260.     orig$ = o.Caption
  261.     ChangesObject cmdObj2, o
  262.     final$ = o.Caption
  263.     MsgBox "Orig: " & orig$ & " Now: " & final$
  264. End Sub
  265. Private Sub cmdRecObj_Click()
  266.     ReceivesObject cmdRecObj
  267. End Sub
  268. Private Sub Command1_Click()
  269.     ReDim x(5) As Integer
  270.     Dim y%
  271.     x(0) = 5
  272.     x(1) = 6
  273.     x(2) = 7
  274.     x(3) = 8
  275.     x(4) = 9
  276.     y% = ReceivesVBArray(x())
  277.     MsgBox "New result of x(0) (was 5) is " & x(0)
  278. End Sub
  279. Private Sub Command2_Click()
  280.     Dim v As Variant
  281.     Dim res%
  282.     v = "hello"
  283.     res% = ReceivesVariantByVal(v)
  284. End Sub
  285. Private Sub Command3_Click()
  286.     Dim v As Variant, rs As Variant
  287.     Dim res%
  288.     v = "hello"
  289.     rs = ReceivesVariant(v)
  290.     MsgBox "V is " & v
  291.     MsgBox "rs is " & rs
  292. End Sub
  293. Private Sub Command4_Click()
  294. End Sub
  295. ' This is a test of passing a pointer to a numeric array
  296. ' Note the unique DLL call
  297. Private Sub ReceivesIArray_Click()
  298.     ReDim x(4) As Integer
  299.     Dim u As UserType
  300.     Dim i As Integer
  301.     x(0) = 1
  302.     x(1) = 3
  303.     x(2) = 9
  304.     x(3) = 81
  305.     ' Pass a pointer to the first element of the array.
  306.     ' The DLL has no way of knowing how long the array is
  307.     ' unless you define a length parameter for the function.
  308.     ReceivesIntArray x(0)
  309.     MsgBox "First entry is now " & x(0)
  310.     ' Note that only the first value is correct, and
  311.     ' that the change does not take effect
  312.     u.e(0) = 88
  313.     u.e(1) = 89
  314.     u.e(2) = 90
  315.     u.e(3) = 91
  316.     ReceivesIntArray u.e(0)
  317.     MsgBox "First entry is now " & u.e(0)
  318.     u.a = 60
  319.     u.b = 61
  320.     u.c = 62
  321.     u.d = 63
  322.     ReceivesIntArray u.a
  323.     MsgBox "First entry is now " & u.a
  324. End Sub
  325. ' A DLL function returning a Visual Basic String
  326. Private Sub ReturnVBString_Click()
  327.     a$ = ReturnsVBString()
  328.     MsgBox a$, 0, "ReturnsVBString"
  329. End Sub
  330. '   Show how to access strings inside user defined types
  331. Private Sub TestAddUserString_Click()
  332.     Dim u As UserType
  333.     ' Note - this is call by reference, the DLL can change
  334.     ' the value of u
  335.     u.s = "orignal string"
  336.     AddUserString u
  337.     MsgBox u.s, 0, "String in usertype changed"
  338. End Sub
  339. ' Passing currency by reference
  340. Private Sub TestCurrencyByref_Click()
  341.     Dim c@
  342.     c@ = 1.23
  343.     AddPennyToCurrency c@
  344.     MsgBox Str$(c@), 0, "AddPennyToCurrency"
  345. End Sub
  346. ' Passing currency by value and returning currency
  347. Private Sub TestCurrencyByval_Click()
  348.     Dim c@
  349.     c = 1.2345
  350.     c = ReceivesCurrency(c)
  351. End Sub
  352. ' Passing doubles by reference
  353. Private Sub TestDoubleByref_Click()
  354.     d# = 3.145
  355.     Add5ToDouble d#
  356.     MsgBox Str$(d#), 0, "Add5ToDouble"
  357. End Sub
  358. ' Passing doubles by value and returning doubles
  359. Private Sub TestDoubleByval_Click()
  360.     d# = ReceivesDouble(3.145)
  361. End Sub
  362. ' Passing integers by reference
  363. Private Sub TestIntByref_Click()
  364.     x% = 5
  365.     Add5ToInteger x%
  366.     MsgBox Str$(x%), 0, "Add5ToInteger"
  367. End Sub
  368. ' Passing integers by value and returning integers
  369. Private Sub TestIntByval_Click()
  370.     x% = ReceivesInteger(5)
  371. End Sub
  372. ' Passing longs by reference
  373. Private Sub TestLongByref_Click()
  374.     y& = 6
  375.     Add5ToLong y&
  376.     MsgBox Str$(y&), 0, "Add5ToLong"
  377. End Sub
  378. ' Passing longs by value and returning longs
  379. Private Sub TestLongByval_Click()
  380.     y& = ReceivesLong(6)
  381. End Sub
  382. ' Passing singles by reference
  383. Private Sub TestSingleByref_Click()
  384.     f! = 1.59
  385.     Add5ToSingle f!
  386.     MsgBox Str$(f!), 0, "Add5ToSingle"
  387. End Sub
  388. ' Passing singles by value and returning singles
  389. Private Sub TestSingleByval_Click()
  390.     f! = ReceivesSingle(1.59)
  391. End Sub
  392. ' Passing strings (null terminated)
  393. ' Always by reference
  394. Private Sub TestString_Click()
  395.     ReceivesString "Hello"
  396. End Sub
  397. ' Passing and modifying strings (null terminated)
  398. ' Always by reference
  399. Private Sub TestStringChange_Click()
  400.     ' Null terminated string is passed to the routine
  401.     ' x$ must be preinitialized to the maximum length.
  402.     ' The DLL may change the contents of the string, but
  403.     ' must never go past the null terminator
  404.     x$ = "Hello"
  405.     ChangesString x$
  406.     MsgBox x$, 0, "ChangesString"
  407. End Sub
  408. ' Passing user defined types
  409. ' Always by reference
  410. Private Sub TestUserType_Click()
  411.     Dim u As UserType
  412.     u.a = 1
  413.     u.b = 2
  414.     u.c = 3
  415.     u.d = 4
  416.     u.e(0) = 5
  417.     u.e(1) = 6
  418.     u.e(2) = 7
  419.     u.e(3) = 8
  420.     u.s2 = "ABCD"
  421.     u.st = 99
  422.     ' Note - this is call by reference, the DLL can change
  423.     ' the value of u
  424.     ReceivesUserType u
  425.     u = ReturnUserType()
  426.     MsgBox "New user type received: " & u.a & u.b & u.c & u.d
  427. End Sub
  428. ' Passing Visual Basic strings
  429. Private Sub TestVBString_Click()
  430.     ReceivesVBString "String to DLL"
  431. End Sub
  432. ' Passing and modifying Visual Basic strings
  433. ' Note - no length restrictions apply
  434. Private Sub TestVBStringChange_Click()
  435.     a$ = "Short"
  436.     ChangesVBString a$
  437.     MsgBox a$, 0, "ChangesVBString"
  438. End Sub
  439.