I've being trying all day following some tutorials and many answers about this subject, but cant figure what I'm doing wrong. Delphi won't even compile, I`ll need to sign some XML docs and i thought a ref or an out string parameter would be the best way to do so. Thanks in advance for any help.
DLL:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Xml;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace Test
{
public class Test
{
[DllExport(CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)]
[ComVisible(true)]
public static void ShowCertificatesList([MarshalAs(UnmanagedType.BStr)] ref string pXmlDoc)
{
pXmlDoc = "test";
var store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certificates = store.Certificates;
X509CertificateCollection vListaCertificados;
vListaCertificados = X509Certificate2UI.SelectFromCollection(certificates, "test", "Certificate list", X509SelectionFlag.SingleSelection);
}
}
}
it works from Windows form:
private void button1_Click(object sender, EventArgs e)
{
string TestStr= "123";
Test.Test.ShowCertificatesList(ref TestStr);
}
But not from Delphi:
var
Form3: TForm3;
procedure ShowCertificatesList(var pStrRef : String) ; stdcall; external 'Test.dll' name 'ShowCertificatesList';
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
vStrRef: String;
begin
vStrRef:= 'in' ;
ShowCertificatesList(vStrRef);
vStrRef := vStrRef;
end;