Onvif-Library

Building

With the latest version of Visual Studio installed do the following

  • run Build01.bat
  • add #import "wsse.h" and change #import "wsdd10.h" to #import "wsdd.h" in onvif.h
  • run Build02.bat
  • run Build03.bat

Any changes that are made to which wsdl and schema files are used needs to be reflected in the build files and in the Visual Studio project file

Recreating from scratch

Downloading and Installing

Visual Studio
  • Download the newest version of Microsoft Visual Studio, the project was originally built using 2017 Community Edition
  • Install, making sure to include the build tools
OpenSSL
  • Download OpenSSL source code, any version newer than 1.1.0 will work.
  • Using the Visual Studio build tools (Native and Cross), compile all combinations of 32bit/64bit and Debug/Release OpenSSL. Much of the Windows OpenSSL documentation is out of date, this tutorial can help.
gSoap
  • Download the latest gSoap, 2.8.66 was used to build this project.
  • Licensing for gSoap differs depending on the planned usage, so read the licensing before decinding whether to use the open source or commercial version of gSoap.
Onvif WSDL and Schema files
  • Download all of the ONVIF files for desired functionality

Creating the folder structure

  • Create a main directory for the project. This is where all of the following folders will be placed.
    • Within the main directory copy the gSoap excecutables soapcpp2.exe and wsdl2h.exe.
  • Create a folder for OpenSSL. Within this folder create subfolders to house the libraries and the include files.
    • Within the include folder copy over all of the header files in anyone of the include folders created when building OpenSSL. The version does not matter as the same include files are created in each build.
    • Within the libraries folder create folders for each of the the OpenSSL versions built, and within them place all of the files in the 'lib' folders within each OpenSSL build.
  • Create a folder for gSoap runtime files, and within place the following gSoap files
    • dom.cpp
    • duration.c/.h
    • mecevp.c/.h
    • smdevp.c/.h
    • stdsoap2.cpp/.h
    • threads.c/.h
    • wsaapi.c/.h
    • wsseapi.cpp/.h
  • Create a folder for all of the wsdl and schema files
    • Place the wsdl and schema files within the folder
    • Get the typemap.dat file from gSoap and place it within the folder
  • Create a folder which the files generated by gSoap will be pumped too

'Compiling' to source code

  • Open up the Visual Studio Developer Command Prompt and navigate to your main directory.
  • Run wsdl2h.exe on all of the desired wsdl and the typemap.dat, instructions can be found here
    • The existing build used the options: -d and -o onvif.h
    • Initially there will be errors because the WSDLs downloaded off the web do not point to the other local files, edit the WSDLs to point to the correct location.
  • In the produced file (onvif.h) add #import "wsse.h" and change #import "wsdd10.h" to #import "wsdd.h"
  • Run soapcpp2.exe on the generated file
    • The existing build used the options: -2 -L -x -i
    • Make sure to use the -d option to send all of the files to the correct location
  • In the output folder, create a file called nsmap.cpp
    • which should contain the line #include "DeviceBinding.nsmap"

Creating the Visual Studio Project

  • Create a new Visual Studio project whose output is a .dll
  • Add all of the files generated by gSoap with the gSoap runtime files.
  • Project Configurations should look as follows
    <ProjectConfiguration Include="Debug|Win32">
        <Configuration>Debug</Configuration>
        <Platform>Win32</Platform>
      </ProjectConfiguration>
      <ProjectConfiguration Include="Debug|x64">
        <Configuration>Debug</Configuration>
        <Platform>x64</Platform>
      </ProjectConfiguration>
      <ProjectConfiguration Include="Release|Win32">
        <Configuration>Release</Configuration>
        <Platform>Win32</Platform>
      </ProjectConfiguration>
      <ProjectConfiguration Include="Release|x64">
        <Configuration>Release</Configuration>
        <Platform>x64</Platform>
      </ProjectConfiguration>
    </ItemGroup>
    
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
      <ConfigurationType>StaticLibrary</ConfigurationType>
      <UseDebugLibraries>true</UseDebugLibraries>
      <PlatformToolset>v141</PlatformToolset>
      <CharacterSet>Unicode</CharacterSet>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
      <ConfigurationType>StaticLibrary</ConfigurationType>
      <UseDebugLibraries>true</UseDebugLibraries>
      <PlatformToolset>v141</PlatformToolset>
      <CharacterSet>Unicode</CharacterSet>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
      <ConfigurationType>StaticLibrary</ConfigurationType>
      <UseDebugLibraries>false</UseDebugLibraries>
      <PlatformToolset>v141</PlatformToolset>
      <WholeProgramOptimization>true</WholeProgramOptimization>
      <CharacterSet>Unicode</CharacterSet>
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
      <ConfigurationType>StaticLibrary</ConfigurationType>
      <UseDebugLibraries>false</UseDebugLibraries>
      <PlatformToolset>v141</PlatformToolset>
      <WholeProgramOptimization>true</WholeProgramOptimization>
      <CharacterSet>Unicode</CharacterSet>
    </PropertyGroup>
    
    • Pre-processor definitions should look like this, with 'WIN32' and 'NDEBUG' being adjusted to meet platform specifics
      • WIN32;NDEBUG;_LIB;WITH_OPENSSL;WITH_DOM;WITH_PURE_VIRTUAL;%(PreprocessorDefinitions)

Building Library

  • Run the following commands in the Developer prompt with your own file path
    • msbuild.exe OnvifLib/OnvifLib.vcxproj /p:Configuration=Debug /p:Platform=Win32
    • msbuild.exe OnvifLib/OnvifLib.vcxproj /p:Configuration=Release /p:Platform=Win32
    • msbuild.exe OnvifLib/OnvifLib.vcxproj /p:Configuration=Debug /p:Platform=x64
    • msbuild.exe OnvifLib/OnvifLib.vcxproj /p:Configuration=Release /p:Platform=x64
  • This will be a rather lengthy process, but once it is completed. the library will be complete.