title: C++ DLL call from C#
body: <p>I want to use a C++ DLL from C#. The C++ DLL is win32 console application. I have successfully called it and want to process the data that I have from c++ in c#. The C# application exits, however, after executing the DLL i.e this line: <code>GetArrayFromDLL();</code></p>
  
  <p>I am new to C# and visual C++. Can someone provide some suggestions?</p>
  
  <p>Thanks</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
  
          [DllImport("Lidar_DataCal_CDLL.dll")]
  
          public static extern void GetArrayFromDLL();
  
  
  
          static void Main(string[] args)
          {
              Console.WriteLine("This is C# program");
              GetArrayFromDLL();
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new Form1());
  
          }
      }
  }
  </code></pre>
  
  <p>This is the DLL I written in win32 application. </p>
  
  <pre><code>extern "C"
  {
    __declspec(dllexport) void GetArrayFromDLL()
    {
  
  /// Reading hex from a file 
  
    FILE * pFile;
  
    FILE * f;
  
    signed int array_data[81],array_data1[81],i;
  
    double fangle,fsin,fcos,fangle_rad;
  
    double afx[81],afy[81];
  
    int px,py;
  
    char file_read[20] = "scandataset1.txt";
  
    char file_write[20] = "xycordinates1.txt";
  
  
    pFile = fopen ( file_read,"a+");
  
    if (pFile != NULL)
  
        {
    for (i=0;i&lt;80;i++)
  
        {
         char buffer[3];
  
         fscanf (pFile, "%x",&amp;array_data[i]);
  
        sprintf ( buffer ,"%d", array_data[i]);
  
        printf ( "I have read: %s \n\n", buffer);
  
        array_data1[i] = atoi(buffer);
  
         // finding angle 
  
         fangle = 20 -( (i+1-1)*0.5);
  
         fangle_rad = (PI*fangle/180);
  
         fsin = -sin(fangle_rad);
  
         fcos =  cos(fangle_rad);
  
         afx[i] = array_data[i] * fsin;
  
         afy[i] = array_data[i] * fcos;
  
        // printf ("X: %lf  and Y: %lf  \n\n",afx[i],afy[i]);
  
         f = fopen(file_write,"a+");
  
         if(f != NULL);
  
         fprintf(f,"%lf %lf\n",afx[i],afy[i]);
  
         fclose (f);
  
        } 
        }
    else
        {
  
        printf("Error opening fail");
  
        }
  
    fclose (pFile);
        }
  
      }
  </code></pre>