VISUAL BASIC OLE DLL to Pass Parameters to DLLs


Passing a parameter to an OLE DLL designed to run with Visual CADD is extremely easy. Visual CADD was designed to pass one string parameter to an OLE DLL, as described in Example DLL to Show, Hide, or Toggle Point Display. Thus, your Visual Basic functions must already be designed to accept a string parameter as input.

Using the same Visual Basic project created in Example DLL to Show, Hide, or Toggle Point Display, add the following to GENERAL.CLS:

        Public Function VBHideLayer(strLayer As String)
                Call VCSetLayerDisplay(iError, Val(strLayer), 0)
        End Function

        Public Function VBShowLayer(strLayer As String)
                Call VCSetLayerDisplay(iError, Val(strLayer), 1)
        End Function

        Public Function VBToggleLayer(strLayer As String)
                Call VCSetLayerDisplay(iError, Val(strLayer), _
                        1 - VCGetLayerDisplay(iError, Val(strLayer)))
        End Function

As mentioned above, Visual CADD was designed to pass one string, or text, parameter to an OLE DLL. However, Visual CADD cannot pass numeric values to an OLE DLL. Thus, if a numeric parameter is needed, your OLE DLL must accept a string parameter and convert it to a number.

In Visual Basic, a string is represented as a sequence of single characters and is declared by the data type String. In each of the above functions, strLayer As String indicates that the parameter strLayer is such a string of characters.

When you call the above functions from Visual CADD with a layer number 10, for example, the string strLayer will contain two single characters '1' and '0', treated as alphanumeric characters, not numbers.

The second parameter in VCGetLayerDisplay and VCSetLayerDisplay refers to the layer number to get or set. From either the Visual CADD API Help file or by looking in VCMAIN32.BAS, you will find that this layer number is an integer. So, converting strLayer from a string to an integer is required.

The Visual Basic function Val converts a string into a number. Thus, if strLayer is the string '10', Val(strLayer) is the integer 10. The remainder of the above code mirrors the code in Example DLL to Show, Hide, or Toggle Point Display.

The final step is to create the OLE DLL using the File, Make OLE DLL File command in Visual Basic. Name your DLL VBVCADD.DLL, for Visual Basic - Visual CADD, and save it in your VBVCADD project folder. If you are adding these new functions to the project created by a previous tutorial, you may replace the original VBVCADD.DLL with your new one.

To run your OLE DLL, include the following in your CMDEXT.DEF (recommended) or Assign Script (AS), where the first line of each is omitted for scripts.

        HideLayer0,H0, ,Hide Layer 0,Hide Layer 0,
                DllName;OLEVCADD.DLL;DllFunName;VBOleDll;
                DllCmdLine;VbVCadd.General|VBHideLayer|0;DllRun;Regen;

        HideLayer1,H1, ,Hide Layer 1,Hide Layer 1,
                DllName;OLEVCADD.DLL;DllFunName;VBOleDll;
                DllCmdLine;VbVCadd.General|VBHideLayer|1;DllRun;Regen;

        ShowLayer0,O0, ,Show Layer 0,Show Layer 0,
                DllName;OLEVCADD.DLL;DllFunName;VBOleDll;
                DllCmdLine;VbVCadd.General|VBShowLayer|0;DllRun;Regen;

        ShowLayer1,O1, ,Show Layer 1,Show Layer 1,
                DllName;OLEVCADD.DLL;DllFunName;VBOleDll;
                DllCmdLine;VbVCadd.General|VBShowLayer|1;DllRun;Regen;

        ToggleLayer0,G0, ,Toggle Layer 0,Toggle Layer 0,
                DllName;OLEVCADD.DLL;DllFunName;VBOleDll;
                DllCmdLine;VbVCadd.General|VBToggleLayer|0;DllRun;Regen;

        ToggleLayer1,G1, ,Toggle Layer 1,Toggle Layer 1,
                DllName;OLEVCADD.DLL;DllFunName;VBOleDll;
                DllCmdLine;VbVCadd.General|VBToggleLayer|1;DllRun;Regen;

Now, from Visual CADD, H0 will hide layer 0, O0 will show layer 0, and G0 will toggle layer 0. Likewise, H1 will hide layer 1, O1 will show layer 1, and G1 will toggle layer 1.

If you require hide, show, and toggle for more than 10 layers, you should change your two-letter aliases to three-letter aliases. For example, Hide Layer 0 would become H00, Hide Layer 1 would become H01, and Hide Layer 15 would be H15, etc. Note that it is necessary to use H01 for Layer 1, because H15 starts with H1 and, otherwise, entering H1 would cause H1 to start before you entered the 5.

Programming Index | VB and VC++ Setup | Example 2 Overview | Tutorial 3