title: How to include files in a Visual C++ Windows Forms application
body: <p>I have created a new Windows Forms application.</p>
  
  <p>After that, I have added a new form. In my form I have added the <code>Form_Load</code> event (by using the form editor).</p>
  
  <p>As far I remember - Visual Studio produced the MainForm.c and MainForm.h files. I had to edit MainForm.c, add main function to it, etc.</p>
  
  <p>I also created a class called <code>CVEngine</code>.</p>
  
  <p><strong>What I want to do</strong></p>
  
  <p>I want to create an instance of the <code>CVEngine</code> class inside my MainForm (see my MainForm.h file, MainForm_Load function at the end of file).</p>
  
  <p><strong>What is my problem?</strong></p>
  
  <p>I guess something is wrong with my includes. I don't know much about C++, and this is my first Windows Forms C++ application. I have a little background in C#, PHP, and a bit of Java. I have basic knowledge about C++ and header files, but this MainForm.h generated by Visual Studio is weird (there is code in .h file), and I'm a bit lost.</p>
  
  <pre><code>1&gt;------ Build started: Project: Sensor Cam, Configuration: Debug Win32 ------
  1&gt;  CVEngine.cpp
  1&gt;  MainForm.cpp
  1&gt;  Generating Code...
  1&gt;CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@QAE@XZ) already defined in MainForm.obj
  1&gt;CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::~CVEngine(void)" (??1CVEngine@@QAE@XZ) already defined in MainForm.obj
  1&gt;CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ) already defined in MainForm.obj
  1&gt;CVEngine.obj : error LNK2005: "public: __thiscall CVEngine::~CVEngine(void)" (??1CVEngine@@$$FQAE@XZ) already defined in MainForm.obj
  1&gt;CVEngine.obj : warning LNK4248: unresolved typeref token (0100001A) for 'CvCapture'; image may not run
  1&gt;MainForm.obj : warning LNK4248: unresolved typeref token (01000021) for 'CvCapture'; image may not run
  1&gt;CVEngine.obj : error LNK2028: unresolved token (0A00052F) "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z) referenced in function "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ)
  1&gt;MainForm.obj : error LNK2028: unresolved token (0A000532) "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z) referenced in function "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ)
  1&gt;CVEngine.obj : error LNK2028: unresolved token (0A00065F) "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
  1&gt;MainForm.obj : error LNK2028: unresolved token (0A000672) "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
  1&gt;CVEngine.obj : error LNK2020: unresolved token (0A00066D) "public: void __thiscall cv::Mat::copySize(class cv::Mat const &amp;)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z)
  1&gt;MainForm.obj : error LNK2028: unresolved token (0A000680) "public: void __thiscall cv::Mat::copySize(class cv::Mat const &amp;)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &amp;)" (??0Mat@cv@@$$FQAE@ABV01@@Z)
  1&gt;MainForm.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z) referenced in function "public: void __thiscall cv::SparseMat::addref(void)" (?addref@SparseMat@cv@@$$FQAEXXZ)
  1&gt;CVEngine.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@$$FYAHPAHH@Z)
  1&gt;MainForm.obj : error LNK2019: unresolved external symbol "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z) referenced in function "public: __thiscall CVEngine::CVEngine(void)" (??0CVEngine@@$$FQAE@XZ)
  1&gt;CVEngine.obj : error LNK2001: unresolved external symbol "extern "C" struct CvCapture * __cdecl cvCreateCameraCapture(int)" (?cvCreateCameraCapture@@$$J0YAPAUCvCapture@@H@Z)
  1&gt;MainForm.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &amp;)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z) referenced in function "public: __thiscall cv::Mat::Mat(class cv::Mat const &amp;)" (??0Mat@cv@@$$FQAE@ABV01@@Z)
  1&gt;CVEngine.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &amp;)" (?copySize@Mat@cv@@$$FQAEXABV12@@Z)
  1&gt;e:\documents\visual studio 2013\Projects\Sensor Cam\Debug\Sensor Cam.exe : fatal error LNK1120: 9 unresolved externals
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>
  
  <p><strong>MainForm.h file:</strong></p>
  
  <pre><code>#pragma once
  
  #include "CVEngine.cpp"
  
  namespace SensorCam {
  
      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      // using namespace System::Data;
      using namespace System::Drawing;
  
      /// &lt;summary&gt;
      /// Summary for MainForm
      /// &lt;/summary&gt;
      public ref class MainForm : public System::Windows::Forms::Form
      {
          public:
              MainForm(void)
              {
                  InitializeComponent();
                  //
                  // TODO: Add the constructor code here
                  //
              }
  
          protected:
              /// &lt;summary&gt;
              /// Clean up any resources being used.
              /// &lt;/summary&gt;
              ~MainForm()
              {
                  if (components)
                  {
                      delete components;
                  }
              }
  
          private:
              System::ComponentModel::Container ^components;
  
              #pragma region Windows Form Designer generated code
                  void InitializeComponent(void)
                  {
                      this-&gt;SuspendLayout();
                      //
                      // MainForm
                      //
                      this-&gt;AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                      this-&gt;AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                      this-&gt;ClientSize = System::Drawing::Size(633, 418);
                      this-&gt;Name = L"MainForm";
                      this-&gt;Text = L"Sensor Cam";
                      this-&gt;Load += gcnew System::EventHandler(this, &amp;MainForm::MainForm_Load);
                      this-&gt;ResumeLayout(false);
                  }
              #pragma endregion
  
          private: System::Void MainForm_Load(System::Object^  sender, System::EventArgs^  e)
          {
              CVEngine cve = CVEngine::CVEngine();
          }
  
      };
  }
  </code></pre>
  
  <p><strong>MainForm.cpp file:</strong></p>
  
  <pre><code>#include "MainForm.h"
  
  using namespace System;
  using namespace System::Windows::Forms;
  
  [STAThread]
  void main(int argc, char *argv[])
  {
      Application::EnableVisualStyles();
      // Application::SetCompatibleTextRenderingDefault(false);
  
      SensorCam::MainForm form;
      Application::Run(%form);
  }
  </code></pre>
  
  <p><strong>CvEngine.cpp file:</strong></p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  using namespace cv;
  
  class CVEngine
  {
      public:
          CVEngine();
          ~CVEngine();
  
      private:
          CvCapture* capture;
  };
  
  CVEngine::CVEngine()
  {
      capture = cvCaptureFromCAM(-1);
      if (!capture)
      {
          // Todo: error handling
      }
  }
  
  CVEngine::~CVEngine()
  {
  
  }
  </code></pre>