On 08 May 2021, Andy Gorman said the following...
I'm creating a DLL that is going to get a value passed into it (path to a file). I am able to pass in a value, but it's getting truncted in the DLL.
Here's the code:
library SimpleLib;
Uses
SysUtils;
Var
Path : String;
o : Text;
function MySucc(AVal : PWideString; pLen : Integer) : PWideString; stdcall; begin
SetLength(String(AVal), pLen);
Assign(o, 'c:\temp\simp.txt');
Rewrite(o);
Write(o,String(AVal));
Close(o);
Result := AVal;
end;
exports
MySucc;
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)