procedure TMainForm.SetCertificate(const FileName, Password: string; var Data: Pointer);
var
Cert : ICertificate2;
CertContext : ICertContext;
PCertContext : PCCERT_CONTEXT;
begin
try
Cert := CoCertificate.Create;
except
on E: EOleSysError do
raise Exception.Create('CAPICOM.DLL no está registrada correctamente.')
end;
Cert.Load(FileName, Password, CAPICOM_KEY_STORAGE_EXPORTABLE, CAPICOM_LOCAL_MACHINE_KEY);
CertContext := Cert as ICertContext;
CertContext.Get_CertContext(Integer(PCertContext));
if InternetSetOption(Data, INTERNET_OPTION_CLIENT_CERT_CONTEXT, PCertContext, 4096) = False then
raise Exception.Create ( 'Error al asignar el certificado de cliente' )
end;