title: Serial Ports in a .DLL file
body: <p>I have created <code>.dll</code> file in Visual C++.<br>
  It includes a function which takes two arguments and send data through serial port. Next i wanted to include this <code>.dll</code> in my application and call these functions. But i am unable to call these functions. Kindly Help.</p>
  
  <p>Here is header file for my <code>.dll</code> </p>
  
  <pre><code> namespace positioncontrol
  
  {  
  using namespace std;
  using namespace System;
  using namespace System::IO::Ports;
  
    public ref class control
  
      {   
      static int rotate(char a, String^ b);
  
      };
  }
  </code></pre>
  
  <p>And here is <code>.cpp</code> for my <code>.dll</code></p>
  
  <pre><code>   #include "goniometer.h"    
  
      namespace positioncontrol
      { 
  
     void control::rotate(char a, String^ b)
      {        SerialPort^ serialPort = gcnew SerialPort(L"COM5",9600,Parity::None,1,StopBits::One);          
               int inp_rotation;
               array&lt;unsigned char&gt;^ inp_c = gcnew array&lt;unsigned char&gt;(2);   
               String^ inp_string;                                             
               inp_c[0] = a;
               inp_string= b;                                     
               inp_rotation=Int32::Parse(inp_string);                         
               inp_c[1] = (unsigned char)inp_rotation;
               serialPort-&gt;Write(inp_c,0,2);                                         
          }
       }
  </code></pre>
  
  <p>I am using this .dll in a desktop application. I have include the header file</p>
  
  <pre><code>#ifndef goniometer_h
  #define goniometer_h
  #include "goniometer.h"
  #endif
  </code></pre>
  
  <p>Added the path for include directories and added .dll as a reference.
  Now i am using the function defined in .dll for a click event</p>
  
  <pre><code>private: System::Void button9_Click(System::Object^  sender, System::EventArgs^  e) {
  
                char dir;       
                dir = 0x42;
                String^ inp_string;                                                
                inp_string=enter_degree-&gt;Text; 
                positioncontrol::control::rotate(dir,inp_string);                                                      
  
           }
  </code></pre>
  
  <p>Now when i build my desktop application i am getting following error</p>
  
  <pre><code>1&gt;C:\Users\DELL\Desktop\Final\Motor_Dual_API\Debug\goniometer.h(10): error C2011: 'positioncontrol::control' : 'class' type redefinition
  1&gt;          c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
  1&gt;c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(530): error C2027: use of undefined type 'positioncontrol::control'
  1&gt;          c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
  1&gt;c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(530): error C3861: 'rotate': identifier not found
  1&gt;c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(540): error C2027: use of undefined type 'positioncontrol::control'
  1&gt;          c:\users\dell\desktop\final\vc++dll\debug\goniometer.dll : see declaration of 'positioncontrol::control'
  1&gt;c:\users\dell\desktop\final\motor_dual_api\motor_next\Form1.h(540): error C3861: 'rotate': identifier not found
  </code></pre>
  
  <p>Kindly help me in figuring out error.
  Thanks and Regards</p>