Configure Visual Studio 8.0 Projects to Build Functions

Building StreamBase C++ functions for 64-bit Windows requires the following setup:

  • You must use Visual C++ 8.0 (Visual Studio 2005) to build the DLL that contains your functions. This constraint is defined by 64-bit Oracle Java 6 for Windows, which uses Visual C++ 8.0 internally.

  • You must configure your Visual C++ projects as described on this page.

  • The machine hosting Visual C++ 8.0 must have a 64-bit installation of StreamBase.

  • In general, these requirements mean you must be working on a supported 64-bit edition of Windows.

Alternate Project Types

StreamBase does not provide a Debug version of the library files for StreamBase Server, and thus does not support building Debug versions of DLLs that contain custom functions. The instructions on this page describe the configuration to build a Release version of your DLLs. If you need to debug your function's code, you must arrange to do so independent of the StreamBase framework.

To configure Visual C++ 8.0 projects to build 32-bit custom C++ functions, you can either:

  • Method 1: Copy the project files from the StreamBase custom-simple-function sample and edit them.

  • Method 2: Create a new project from scratch or modify an existing Visual Studio project.

Method 1: Copy Sample Project Files

  1. Copy the streambase-install-dir\sample\custom-simple-function folder to your Visual C++ workspace. You must copy the folder from a 64-bit installation of StreamBase.

    For clarity, keep your Visual C++ workspace in a separate location from your StreamBase Studio workspace.

    Note

    You must copy this folder from the StreamBase installation directory. Do not make a copy of the custom-simple-function sample in your StreamBase Studio workspace, because the Studio workspace sample does not have the Visual Studio .sln and .vcproj files.

    If you are creating a custom aggregate function, copy the following folder instead: streambase-install-dir\sample\custom-aggregate-function

  2. Locate the custom-simple-function-x64.sln file. You can optionally rename this file before opening it the first time. Preserve the .sln extension, and choose a basename that reflects the purpose of the intended client. For example, rename custom-simple-function-x64.sln to wicked-cool-function-x64.sln.

  3. Start Visual C++ 8.0. Use FileOpenProject to load custom-simple-function-x64.sln (or your renamed solution file, wicked-cool-function-x64.sln). Let the conversion wizard update the solution file.

  4. In the Solution Explorer, rename the logfunction project as appropriate for your custom function. For example, rename it to wicked-cool.

  5. Rename LogFunction.cpp as appropriate for your function. For example, rename it to wicked.cpp.

  6. In the Solution Explorer, right-click your project and select Properties from the context menu.

  7. Notice that the Configuration drop-down menu contains only Release and Active (Release), and does not have an All Configurations option. This is because the custom-simple-function-x64.sln sample is configured to build only a 64-bit DLL, and because you cannot build a Debug version of your DLL, as described above.

    Accordingly, on the Configuration drop-down menu, choose either Release or Active (Release), which are effectively the same configuration:

  8. In the LinkerGeneral properties, optionally rename the DLL file to be generated from log-x64.dll to the filename of your choice, such as wickedcool-x64.dll:

    Property Folder Property Page Property Row Setting
    Linker General Output File $(OutDir)\my-dll-name.dll
  9. Locate the places in the project properties that use ${STREAMBASE_HOME} and replace those with the absolute path to your top-level StreamBase installation directory. In general, do this by clicking in the specified setting row, then click the button with three dots to open the Additional Directories dialog. Select a row in this dialog and use the second three-dot button to navigate to your StreamBase installation's directory:

    1. Confirm the following setting:

      Property Folder Property Page Property Row Setting
      C/C++ General Additional Include Directories Replace the path that uses ${STREAMBASE_HOME} with the absolute path to the include directory of your StreamBase installation: streambase-install-dir\include
    2. Confirm the following setting:

      Property Folder Property Page Property Row Setting
      Linker General Additional Library Directories Replace the path that uses ${STREAMBASE_HOME} with the absolute path to the lib64\Release directory of your StreamBase installation: streambase-install-dir\lib64\Release
  10. Make sure the Solution Configuration drop-down is set to Release and the Solution Platform drop-down is set to x64, then build your project. Verify that a DLL of the specified name is generated in the x64\Release folder.

  11. Begin customizing the source file for your client.

  12. When you have a DLL ready to test in the context of a StreamBase application, follow the steps in Deploying Custom C++ Functions.

Method 2: New or Existing Project

To create a new Visual C++ project from scratch, select FileNewProject. In the New Project dialog, select Visual C++ ProjectsMFC, then select MFC DLL.

Whether using an existing Visual C++ project or starting with a new one, make sure the project's settings match those described in the following steps. All project settings not listed here are optional, and can be changed to match the requirements of your project.

  1. In Visual C++ Studio, select FileNewProject.

    1. In the New Project dialog, select Visual C++ ProjectsWin32, then select Win32 Console Application.

    2. In the Name field, enter a name for your project.

    3. In the Win32 Application Wizard dialog, select Application Settings.

    4. Under Application Type, select DLL.

    5. If you already have a C++ file that contains your function, then under Additional options, select Empty project. If you are starting from scratch, leave this check box cleared.

    6. Click Finish.

  2. If you already have a C++ file for your function, use Windows Explorer to drag that file to the newly created project folder.

  3. Back in Visual C++ Studio, in the Solution Explorer panel, right-click the new project and select Properties from the context menu.

  4. In the project's Property Pages dialog, click the Configuration Manager button.

    1. In the Configuration Manager dialog, select the row for your new project.

    2. In the Release column, click the drop-down arrow and select <Edit>.

    3. In the Edit Project Configurations dialog, remove the Debug option and close the dialog.

    4. In the Platform column, click the drop-down arrow and select <New>.

    5. In the New Project Platform dialog, select x64 from the first drop-down menu, then close the dialog.

    6. In the Platform column, click the drop-down arrow and select <Edit>.

    7. In the Edit Project Platforms dialog, remove the Win32 option and close the dialog.

    8. Close the Configuration Manager dialog.

    You can now select only Release and x64 from the Configuration and Platform drop-down menus.

  5. Make sure the following settings are in place:

    Property Folder Property Page Property Row Setting
    Configuration Properties General Configuration Type From the drop-down menu, select Dynamic Library (.dll).
    Configuration Properties General Use of MFC From the drop-down menu, select Use Standard Windows Libraries.
    Configuration Properties General Use Managed Extensions No
    C/C++ General Additional Include Directories Path to the include directory of your StreamBase installation.

    streambase-install-dir\include

    Do not use the environment variable STREAMBASE_HOME to define this path (unless you have applied this variable globally as described in StreamBase Command Prompt). If there is already an entry in this row that uses ${STREAMBASE_HOME}, replace that entry.

    Instead, click in the row and use the button with three dots on the right side to open the Additional Include Directories dialog. Select a row in this dialog and use the second three-dot button to navigate to your StreamBase installation's include directory.

    C/C++ Preprocessor Preprocessor Definitions Append the following definition to the default list:

    STREAMBASE_PTHREAD_DLL

    C/C++ Code Generation Runtime Library From the drop-down menu, select Multi-threaded DLL (/MD).
    C/C++ Precompiled Headers Create/Use Precompiled Headers From the drop-down menu, select Not Using Precompiled Headers.
    Linker General Additional Library Directories Append the following path to the entries in that row:

    streambase-install-dir\lib64\Release

    As described above, do not use STREAMBASE_HOME to define this path.

    Linker Input Additional Dependencies

    Fill in the Additional Dependencies row with the following entries:

    LibsbClient-vc8.lib
    sbserver.lib
    pthreads-vc8.lib
    WS2_32.lib
    xercesLib-vc8.lib
    Dbghelp.lib

    In the Additional Dependencies dialog, make sure the Inherit from project defaults check box is selected.

  6. Begin customizing the source file for your client.

  7. When you have a DLL ready to test in the context of a StreamBase application, follow the steps in the next section.

Deploying Custom C++ Functions

To deploy your custom functions in the context of your StreamBase application, follow these steps:

  1. Copy the DLL file generated in the steps above to the root of your StreamBase Studio project folder.

  2. Edit your server configuration file to reference the new function:

    1. Reference the DLL file name in plugin child element of the global element. For example:

      <global>
        <plugin file="./wicked-cool.dll" />
      </global>
      

      See the global section of the StreamBase Server Configuration File XML Reference for details.

    2. Declare the function in a custom-function element as described in the custom-functions section of the StreamBase Server Configuration File XML Reference.

  3. Make sure you have referenced your custom function's name with consistent spelling and capitalization in the following places:

    • The required C++ macro in the C++ file that defines your function. For example:

      STREAMBASE_DEFINE_PLUGIN_FUNCTION(LogFunction, "log");
      
    • The custom-function element of the server configuration file. For example:

      <custom-function name="log" type="simple" >
        <args>
        ...
      
    • In the expression in an EventFlow or StreamSQL module that calls your function. For example:

      callcpp("log", 1, 3)
      

Your DLL can contain multiple custom functions, following these rules:

  • Add multiple C++ files to the Visual C++ project that generates the same DLL, with one function per C++ file.

  • For each function defined in the DLL, provide a separate custom-function element in the server configuration file.