Memory Allocation for External Functions

When calling a string-related external function in .NET targets, you must modify the function's source code in the DLL to allocate memory for the string.

Example 1

If the original source code looks like this:

char* WINAPI fnReturnEnStrA() 
{ 
  return "ANSI String";   
}

Sybase recommends that you change it to:

#include <objbase.h> 
... ... 
char* WINAPI fnReturnEnStrA() 
{ 
  char* s = (char*)CoTaskMemAlloc(12); 
  memcpy(s, "ANSI string\0", 12); 
  return s; 
}