@DerkJ – As @Tim_Hare hinted at, most of what I’ve been discussing is about passing the Structure out of Xojo and into my C++ DLL.
However, it totally works correctly going the other way: my C++ DLL has a definition for a “return_value” structure:
C++ structure definition in DLL code:
struct return_value
{
char* fReturnValueString;
int64_t fReturnValueInt;
int64_t fReturnValueBool;
};
Structure definition in Xojo IDE:
Structure return_value
fReturnValueString As CString
fReturnValueInt As Int64
fReturnValueBool As Int64
End Structure
The return structure is defined and allocated in Xojo, then passed into the Xojo wrapper function as:
ByRef retVal as MyApp.return_value
The DLL receives the structure as:
return_value* retVal
And the return value is allocated and stored in the return structure like so:
std::string myCPPString = "some text to return";
retVal->fReturnValueString = (char*)malloc(myCPPString.size() + 1); // +1 to account for null byte
strcpy(retVal->fReturnValueString, myCPPString.c_str());
So the returned CString is ALLOCATED in the C++ code, the contents are copied into the allocated buffer, and then the allocated pointer is returned via the Structure. The Xojo wrapper function might return a Xojo String, but all that’s needed is simply to:
return retVal.fReturnValueString
…and Xojo will take the pointer to the DLL-allocated CString in the returned structure and convert it to a Xojo String automatically.
THIS ALL WORKS PERFECTLY.