VISUAL C++ DLL to Pass Parameters to DLLs


Passing a parameter from Visual CADD to a DLL is extremely easy. The Visual CADD native command DllCmdLine passes the subsequent string to the DLL. Your DLL function must simply accept a string parameter.

Using the same Visual C++ project created in Example DLL to Show, Hide, or Toggle Point Display, add the following to VCVCADD.CPP:

        //      HideLayer   
        HRESULT WINAPI HideLayer(char pStr[])
        {
                VCSetLayerDisplay(pErr,atoi(pStr),0);
                return(NOERROR);
        }

        //      ShowLayer
        HRESULT WINAPI ShowLayer(char pStr[])
        {
                VCSetLayerDisplay(pErr,atoi(pStr),1);
                return(NOERROR);
        }

        //      ToggleLayer
        HRESULT WINAPI ToggleLayer(char pStr[])
        {
                VCSetLayerDisplay(pErr,atoi(pStr), 1 - VCGetLayerDisplay(pErr,atoi(pStr)));
                return(NOERROR);
        }

As mentioned above, Visual CADD can pass strings, or text, to a DLL through the use of DllCmdLine. However, Visual CADD cannot pass numeric values to a DLL. Thus, if a numeric parameter is needed, your DLL must accept a string parameter and convert it to a number.

In Visual C++, a string, or text, can be represented as a sequence of single characters. The data type char represents individual characters. In the parameter char pStr[], the [] indicates that pStr is an array, or sequence, of single characters, i.e., a string.

When you call the above functions from Visual CADD with a layer number 10, for example, the string pStr 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.H, you will find that this layer number is a short integer. So, converting pStr from a string to an integer is required.

The Visual C++ function atoi converts a string into an integer. Thus, if pStr is the string '10', atoi(pStr) is the integer 10. The remainder of the above code mirrors the code in Example DLL to Show, Hide, or Toggle Point Display.

The function declarations also should be added to VCVCADD.H:

        HRESULT WINAPI HideLayer(char pStr[]);
        HRESULT WINAPI ShowLayer(char pStr[]);
        HRESULT WINAPI ToggleLayer(char pStr[]);

Lastly, for the functions to be available to external calling applications, such as Visual CADD, the function names need to be exported by adding them to the EXPORTS section MFCVCADD.DEF:

        HideLayer
        ShowLayer
        ToggleLayer

To run your 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;C:\VC++4\MFCVCADD\RELEASE\MFCVCADD.DLL;
                DllFunName;HideLayer;DllCmdLine;0;DllRun;Regen;

        HideLayer1,H1, ,Hide Layer 1,Hide Layer 1,
                DllName;C:\VC++4\MFCVCADD\RELEASE\MFCVCADD.DLL;
                DllFunName;HideLayer;DllCmdLine;1;DllRun;Regen;

        ShowLayer0,O0, ,Show Layer 0,Show Layer 0,
                DllName;C:\VC++4\MFCVCADD\RELEASE\MFCVCADD.DLL;
                DllFunName;ShowLayer;DllCmdLine;0;DllRun;Regen;

        ShowLayer1,O1, ,Show Layer 1,Show Layer 1,
                DllName;C:\VC++4\MFCVCADD\RELEASE\MFCVCADD.DLL;
                DllFunName;ShowLayer;DllCmdLine;1;DllRun;Regen;

        ToggleLayer0,G0, ,Toggle Layer 0,Toggle Layer 0,
                DllName;C:\VC++4\MFCVCADD\RELEASE\MFCVCADD.DLL;
                DllFunName;ToggleLayer;DllCmdLine;0;DllRun;Regen;

        ToggleLayer1,G1, ,Toggle Layer 1,Toggle Layer 1,
                DllName;C:\VC++4\MFCVCADD\RELEASE\MFCVCADD.DLL;
                DllFunName;ToggleLayer;DllCmdLine;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