For writing a DLL function that returns a string result, I need a C
function that takes a pointer to a given string, creates a copy of it
and returns a pointer to the copied string. (The string may be > 64 KB
and should be freed again by the calling program.)

This is probably a rather simple task, but I didn't succeed yet. I tried
something like:

#include <stdlib.h>
#include <string.h>
char*
mallocAndStrCpy (const char* srcStr) {
  return strcpy((char*) malloc(strlen (srcStr)+1),srcStr);
}

However, for the string result I probably have to use something else
than "malloc"?!

Secondly, how should the caller free the assigned memory again?

I'm sorry for this basic question, but I'm still a beginner in
programming with cygwin/gcc under WinNT.

Regards, Christian


--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

Reply via email to