Or always allocate and free the buffer in the calling program and load the contents into the buffer in the dll. This way you never have to worry about allocating in one place and freeing in the other. Windows API does stuff like this a lot.
In the DLL: Procedure GetSomeString(StringPointer: Pointer, Var StringLen: Integer); Begin StringLen = CalculateSizeOfString if StringPointer != nil then // copy string to StringPointer End; In your App: Var StringLen: Integer; AllocedMem : Pointer; . . . // Find out how much memory needed GetSomeString(nil, &StringLen); GetMem(AllocedMem, StringLen); GetSomeString(AllocedMem, &StringLen); // use the string for whatever you need . . . FreeMem(AllocedMem); Very bad psuedo code there, but it should give you the idea. To summarize, your app needs to: 1. Call once with nil to get how much memory needed 2. Allocate the memory 3. Call again with pointer to memory 4. Use the allocated memory 5. Free the allocated memory And your dll function needs to: 1. Check pointer for nil 2. If so, only set the length parameter to the size of memory needed and exit 3. If not, copy data to pointer as well Jeff.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal