Subj : Re: "Delphi" DLL To : Andy Gorman From : Alexander Grotewohl Date : Sat May 08 2021 20:02:46 On 08 May 2021, Andy Gorman said the following... AG> I'm creating a DLL that is going to get a value passed into it (path to a AG> file). I am able to pass in a value, but it's getting truncted in the AG> DLL. AG> AG> Here's the code: AG> AG> library SimpleLib; AG> AG> Uses AG> SysUtils; AG> AG> Var AG> Path : String; AG> o : Text; AG> AG> function MySucc(AVal : PWideString; pLen : Integer) : PWideString; AG> stdcall; begin AG> SetLength(String(AVal), pLen); AG> Assign(o, 'c:\temp\simp.txt'); AG> Rewrite(o); AG> Write(o,String(AVal)); AG> Close(o); AG> Result := AVal; AG> end; AG> AG> exports AG> MySucc; AG> End. are you calling this from C# then? it would seem SetLength() is doing something to a pointer that is not technically a 'PWideString'. (a PWideString has a known length, see https://wiki.freepascal.org/Character_and_string_types) String() on the other hand (depending on compiler settings) would force AVal to a old pascal style string where string[0] is a byte for the length. so if the length is stored in memory at str[-1] and str[0] (this is not something you'd normally interact with.. these are managed types and the compiler handles this), you're only getting one byte of the length. is there a reason you're using PWideString? SysUtils has a StrPas function that makes it fairly easy to do things like UnicodeStringVar:=StrPas(AVal); where AVal is a PWideChar .. which is usually enough for me to interact with C/C++ from pascal. sorry for the lack of code.. but i'd be unable to test it if it's called from other than pascal ;) but hopefully it's enough --- Mystic BBS v1.12 A47 2021/04/20 (Windows/32) * Origin: cold fusion - cfbbs.net - grand rapids, mi (1:120/616) .