I'm trying to use the standard system dialogs for manipulating SecureBlackBox 9 objects.

I've been able to use the CryptUIDlgViewCertificate function to display a certificate from SBB but now that I'm going to the certificate selection dialog, I'm getting lost in the details.

Specifically, I need a handle to an existing store for the CryptUIDlgSelectCertificateFromStore function call to succeed. It seemed to me that the logical way to go about that would be to create an instance of TElWinCertStorage, call CreateStore, add my certificate list to it and then use the handle to the CryptUIDlgSelectCertificateFromStore call. Unfortunately, I can't find a way to get that handle back. Looking at the source code, the handle is created as a local variable and isn't stored as a component state and there is no obvious way to obtain it again without re-creating it completely from my code (with straight CAPI calls) or modifying the SBWinStorage source code.

TElWinCertStorage is an interface to access certificates in all system storages (ROOT, MY, CA etc.) and does not have mechanism to obtain storage handles. CryptUIDlgSelectCertificateFromStore requires a handle to a particular certificate store. The best way is to use WinAPI (CertOpenSystemStore) to obtain needed handle.

In fact, you can access the originating store handle with the use of PCCERT_CONTEXT reference exposed by every certificate originating from a system store. Please use TElX509Certificate.CertHandle.hCertStore property to get the handle.

Well, you will need to have your certificates in some (temporary) system store, as CryptUIDlgSelectCertificateFromStore() expects one on input. Just to make sure I've checked my assumption with the following code snippet and it proved to work (no error handling at all):

We use cookies to help provide you with the best possible online experience. By using this site, you agree that we may store and access cookies on your device. You can find out more about and set your own preferences here.