Quote Originally Posted by LMHmedchem View Post
The calling code passes something like string or char* and the dll will mostly return float, along with some string.
You need to be careful about this. There are certain methods that are used to pass and return string data to and from a DLL.

One thing you don't want to do is have the DLL dynamically allocate string data using C/C++ library functions, and hoping that the application deallocates the data. This won't work for obvious reason, the most obvious reason being that the caller program has no idea how to deallocate the data (was the data allocated new? new[]? malloc()?), let alone that it may not even be a 'C' or C++ program calling the DLL (so malloc(), new, new[] doesn't even exist).

The only exception to this rule is if the DLL uses a function such as GlobalAlloc(), HeapAlloc(), or any OS-specific memory allocation function that all languages has access to, then the deallocation is done by calling the OS-specific function.

I always have persons look at the string-related Windows API functions to see the sure-fire way of dealing with string data properly. One way is that the caller provide the string buffer to fill in instead of the DLL attempting to create strings. The other way is that the DLL implements a "mini-API", where the caller has to use exported functions from the DLL to create, manipulate, and destroy the data.

As to float -- the usual 8 byte IEEE doubles should work. There was an issue a while back concerning differences when returning floats when using different C++ compilers (I think it was Borland's C++ compiler compared to Visual C++), but again, that was a long time ago and I don't think it's an issue now.

Regards,

Paul McKenzie