3.2.4   Integrate Library Project into Visual Studio

Lastly, we have to integrate the HDevelop program into our Visual Studio Project.

  1. Open the Visual Studio Project.
  2. Open Project ▹ Add Existing Item... and choose the C++ file hdev_count_regions.cpp and the header file hdev_count_regions.h, created by HDevelop's Library Export. (The files are located in the folder hdev_count_regions ▹ source.)
  3. Enter the following code into vs_count_regions.cpp:

    #include <iostream>
    
    #include "HalconCpp.h"
    #include "hdev_count_regions/source/hdev_count_regions.h"
    
    int main()
    {
    	HalconCpp::HImage Image("pcb");
    	
    	hdev_count_regions::SetResourcePath("hdev_count_regions/res_hdev_count_regions");
    	
    	HalconCpp::HTuple Number{};
    	hdev_count_regions::count_regions(Image, &Number);
    	
    	std::cout << "Number of Regions: " << Number.L() << '\n';
    }
    

  4. Execute the program. → A console opens, showing the result 'Number of regions: 43'.