title: Function to concat two char* in C++
body: <p>First off, I'm a C# programmer, so my working knowledge of C++ is fairly limited. I took it back in college, but haven't touched it in 10 years, so please forgive me if this is relatively simple stuff.</p>
  
  <p>I'm attempting to make a DLL that I can use in C# that implements the libwpd library.</p>
  
  <p>I've managed to create a DLL that exports 2 functions that I can access via  P/Invoke.  The first returns a constant integer (generated by visual studio as a sample), the 2nd a string.</p>
  
  <p>If I return a constant string from the function, it passes successfully to C# and I can read it on the other end, so I know the data is being passed back.</p>
  
  <p>The problem I'm running into is with libwpd.  I've had to modify their TextDocumentGenerator.cpp file to add the information to a char* instead of using the printf that they use so I can access it later.</p>
  
  <p>I've added a variable definition to the public section of the header file so I can read it from the calling code.</p>
  
  <p>Now, I'm trying to write a function that allows me to add the char* given by libwpd to the external char*.</p>
  
  <p>I've come up with this:</p>
  
  <pre><code>char* addString(const char* addThis, char* toThis)
  {
  char* copier  = (char*)malloc(strlen(toThis) + 1 + 1);
  strcpy(copier, toThis);
  strcpy(copier, "1");
  
  toThis = (char*)malloc(strlen(copier) + 1);
  strcpy(toThis, copier);
  
  return copier;
  } 
  </code></pre>
  
  <p>But when I pass the information back, I get a blank string.</p>
  
  <p>I call the function by calling <code>totalFile = addString("\n", totalFile);</code></p>
  
  <p>(I realize it should only technically add "1" to the string repeatedly, but it's not doing even that)</p>
  
  <p>If i change the strcpy to strcat for the copier lines, it locks up.</p>
  
  <p>I don't know how to create a program in C++ so I can even step through the functions to see what's happening.</p>
  
  <p>Any assistance would be appreciated.</p>