title: Passing char*and struct in C# to c++ DLL, all variables pass successfully except one
body: <p>I have written a c++ wrapper dll for a C dll with lib file I have, now everything is partially working, all the functions I have written in the c++ wrapper class work as expected bar one.</p>
  
  <p>Here it is in the C++ dll</p>
  
  <pre><code>__declspec(dllexport) long ReadRawDataByTime(char * tagname, long serverhandle, IHU_TIMESTAMP * StartTime, IHU_TIMESTAMP * EndTime, int * number_of_samples, IHU_DATA_SAMPLE **data_values){
          return ihuReadRawDataByTime(serverhandle, tagname, StartTime, EndTime, number_of_samples, data_values);
  }
  </code></pre>
  
  <p>and here is my definition and how I call it in C#</p>
  
  <pre><code>        [DllImport("IHUAPIWrapper.dll")]
          public static extern long ReadRawDataByTime(String tagname, long serverhandle, IHU_TIMESTAMP* StartTime, IHU_TIMESTAMP* EndTime, int* number_of_samples, IHU_DATA_SAMPLE** data_values);
  ...
                  long lRet = ReadRawDataByTime
                  (
                      tagname,//the handle returned from the connect
                      serverhandle,           //the single tagname to retrieve 
                      &amp;temp_start_time,   //start time for query
                      &amp;temp_end_time,     //end time for query
                      &amp;number_of_samples, //will be set by API
                      &amp;pSamples           //will be allocated and populated in the user API
                  );
  </code></pre>
  
  <p>where tagname is defined as a string and the rest are their appropriate structs.</p>
  
  <p>Now if I set the debugger in the C++ dll I can see all the values being passed in correctly, serverhandle is as expected, tagname holds the correct string, endTime has the correct time, number of samples and pSamples are blank as expected however startTime is 'undefined' when I am definitely passing in a valid struct.</p>
  
  <p>If I dummy up the variables in the debugger it even returns expected data it just appears it is not passing the variables correctly.</p>
  
  <p>I did some experimentation and swapped the order of the variables so serverhandle was passed first and tagname was passed second, if I do this all the variables are correct except tagname is now 'undefined'</p>
  
  <p>is there something wrong with how I am passing the string that is corrupting the next variable? do I need to specifiy some special calling convention and currently it is just a fluke that everything else works?</p>
  
  <p>Any help would be much appreciated. :)</p>
  
  <p>edit: here is a screenshot of the debugger to show what I mean about all variables being passed except one.
  <img src="https://i.stack.imgur.com/jTD0A.jpg" alt="http://img602.imageshack.us/img602/5281/47739520.jpg"></p>