How to pass a string as parameter to a C#DLL

Asked

Viewed 345 times

1

I have a dll made in C# with a method that receives a string type parameter, I created a function in Delphi that calls this method and passes the following string in the parameter: ’D: Banks Test.fdb', I put a messagebox in the dll just to check how the parameter was coming and the only value that comes is the’D' character the rest of the string does not come. Is there any way to solve it? Below is an excerpt of the code:

dll in C#:

[Guid("36CEE06F-247C-48B4-A8BB-0E591CEF58BE")]
[ComVisible(true)]
public class ReportService
{
    [DllExport]
    public static bool ListaComprasResumida(string pathBanco, string codEmpresa)
    {
        MessageBox.Show(pathBanco);

        Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

        var frm = new FrmListaComprasResumido(pathBanco, codEmpresa);
        frm.ShowDialog();

        return true;
    }
}

Function call on Delphi:

uses    
function ListaComprasResumida(pathBanco: string; codEmpresa: string): Boolean; stdcall; external 'Modules.dll';

procedure TRelatorio.btnComprasResumidoClick(Sender: TObject);
var
  caminho : string;
  codigo : string;
begin  
  caminho := txtBanco.Text;
  codigo := txtCodEmpresa.Text;
  ListaComprasResumida(caminho, codigo);
end;
  • Try sending as Widestring or Ansistring...

  • 1

    Thank you, Ansistring solved my problem. Thank you very much.

1 answer

2


Pass Delphi parameter to DLL(any language, mainly VB) to use WideString or AnsiString.

AnsiString: string composed of ASCII characters.

String: in the newer versions of Delphi (2007 onwards), equivalent to Unicodestring. Formerly equivalent to Ansistring.

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.