Creating user-defined C functions (D3 Windows)

The example below describes creating, adding, removing, loading and unloading a C DLL function in Visual Studio 2008.

Step 1: Create a new Project:

  1. From the Visual Studio startup panel, select the create Project option.

  2. Select the Visual C++ Project Type.

  3. Select the Win32 Project template.

  4. Specify a Name, Location and Solution Name and then click OK

  5. Click Next at the Custom Application Wizard Welcome screen.

  6. Specify the DLL Application Type.

  7. Select the Empty Project check box from Additional Options.

  8. Click Finish.

    The project is created.

Step 2: Create the user branch table (pxusrtbl.cpp)

  1. Log to the DM account in TCL and add the user built in functions with the addbi command. For example:

    Type the following command:

    addbi MyFunc (f

    The to: path is the path you specified in the Location text box in step 4 above).

    The user branch table is created.

Step 3: Verify the user builtin functions

  1. Run the following command from TCL:

    ct messages user.builtin
    001 15
    002 MyFunc]1

Step 4: Add the pxusrtbl.cpp to the project

  1. From the Solution Explorer, right-click Source Files and select AddExisting Item.

  2. Select pxusrtbl.cpp.

  3. Click Add.

Step 5: Create and add the C++ source code file

  1. From the Solution Explorer, right-click Source Files and select AddNew Item.

  2. Select C++ File.

  3. Give this file a name in the format (filename.c).

  4. Click Add.

  5. Open this source file and enter the C++ code.

    Code example:

    /Comment here
    int MyFunc(int x)
    return x+1;

Step 6: Set Compile options

  1. Select ProjectProperties from the Visual Studio menu bar.

  2. Expand the Configuration Properties item.

  3. Expand the C++ item.

  4. Select the Code generation item.

  5. Click Runtime Library and specify the your Runtime Library:

    • Debug Multithreaded DLL (will use MSVCRTD.dll, the visual C debug runtime library, usually only available on systems where the VC++ development is installed. You can use this library while developing the dll.)

    • Multithreaded DLL (will use MSVCRT.dll, the visual C runtime library. This library is found in the system32 directory of Windows systems. After developing the dll, you should rebuild it using this library for deployment to systems running D3 that do not have VC++ installed.)

  6. Click OK.

  7. Select FileSave All from the Visual Studio menu bar.

Step 7: Build the dll

  1. Select BuildBuild CLoad.dll from the Visual Studio menu bar.

Step 8: Load the dll

  1. Log to the DM account in TCL and run the following command:

    nt_cload 15 C:/temp/CLoad/debug/CLoad.dll

    Note that the 15 is required.

    Note that you can only load 1 dll. As such, all functions must be contained within the specified dll.

Step 9: View the dll

  1. Run the following command from TCL to confirm the dll has been loaded:

    nt_cinfo 15

Step 10: Test the new function

  1. From TCL, test the function:

    u bp test.cload
    001 cfunction user.builtin
    002 print %MyFunc(3)
    compile bp test.cload (o
    run bp test.cload

    Note that the (o option for Flash compiling is required.

Step 10a: Rebuild using the non-debug run-time library if necessary.

  1. After verifying the dll is working properly, you may need to rebuild it for deployment to systems that do not have VC++ loaded. See step 6.

Step 11: To start all over

  1. Unload the dll.

    nt_cunload 15
  2. Delete messages user.builtin.

  3. Delete the project workspace directory.