Sorry, if it is a dumb question, I am pretty new to Delph, and struggling with basics. Below is the Delphi code and I call the same from C#, but it gives an error as "System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'"
function GetString(str: PWideChar; len: Integer): Integer; stdcall;
begin
StrLCopy(str, 'hello world', len);
Result := 1; // real code would have real error handling
end;
exports GetString;
C# code
[DllImport("AppLoader.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int GetString(StringBuilder str, int len);
private void button3_Click(object sender, EventArgs e)
{
StringBuilder str = new StringBuilder(256);
int retval = GetString(str, str.Capacity);
MessageBox.Show(str.ToString());
}