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 / samples4 / vbdll / vbdll.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-05  |  12.7 KB  |  440 lines

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