/// <summary> /// A less error-prone wrapper for CertEnumCertificatesInStore(). /// /// To begin the enumeration, set pCertContext to null. Each iteration replaces pCertContext with /// the next certificate in the iteration. The final call sets pCertContext to an invalid SafeCertStoreHandle /// and returns "false" to indicate the end of the store has been reached. /// </summary> public static unsafe bool CertEnumCertificatesInStore(SafeCertStoreHandle hCertStore, [NotNull] ref SafeCertContextHandle?pCertContext) { Interop.Crypt32.CERT_CONTEXT *pPrevCertContext; if (pCertContext == null) { pCertContext = new SafeCertContextHandle(); pPrevCertContext = null; } else { pPrevCertContext = pCertContext.Disconnect(); } pCertContext.SetHandle((IntPtr)Crypt32.CertEnumCertificatesInStore(hCertStore, pPrevCertContext)); if (!pCertContext.IsInvalid) { return(true); } pCertContext.Dispose(); return(false); }