1, 2) Yes, use arrays. Obtain them dynamically.
3) The calling program and the DLL share the same memory space, so all you need is to pass a pointer to the data you allocate.
You need to be careful, however, not to use
new[] in the DLL and
delete[] in the calling program, or vice-versa. The EXE and the DLL do not share memory management!
You need to explicitly specify what is OK and what is not OK. Two common methods follow:
method one
Use Windows API functions to allocate and deallocate memory, so that the calling process can do the same with memory managed by the DLL. The Win32 functions you need are
HeapAlloc(),
HeapFree(), and even
HeapReAlloc().
http://www.google.com/search?btnI=1&q=msdn+HeapAlloc
This way, both EXE and DLL can manipulate the memory - since we're using the OS's memory management functions.
method two
Export a function specifically to deallocate memory (and more, as you wish) - which the caller is
required to use to handle memory you give it. That way the code for your DLL can use
new[] and
delete[], or
malloc() and
free(), or whatever you want, and the caller can use whatever
it wants, since neither directly allocates or deallocates the other's memory.
Hope this helps.