Dear all,

I am trying to Subclass or hook this DialogBox window which pops up when playing the following code under MS word for windows :

Dim sig as signature
set sig = activedocument.signatures.add

the soft will ask you to save the document prior to digitally sign pleasze do so and then the selectCert Dialogbox will be displayed.
The aim is to be able to tweak this dialog box and to achieve the following goals:

1°) To be able to Collect and check certificates from any stores instead of only “My store” as the actual current behaviour. (To address the case where I have a smartcard or a central LDAP repository )

2°) To pass a date variable with the time stamp to be applied (to have the same time stamp date as the handwritten signature I applied previously to the document, I can pass either a date variable or a system time structure if needed )

3°) To select programmatically the accurate certificate(s) corresponding to the signatory identity (passed as parameter) with filters on Certificate Subject Name, Certificate Issuer, and expiry date , in order to disable possible selection of any else certificate available in the store or LDAP or smartcard.

4°) To be able to move the Dialog box wherever needed on screen (Done)

5°) To be able to Change the Static Textbox1 content message of the DialogBox

6°) To be able to change the Title message of the Dialog Box (Done)

I found very limited resources over the web to address this , except the SelectCert Structure used to build any Of these particular DialogBoxes on MSDN, and some C Code …

Have you any idea on how to achieve that ?
See http://msdn.microsoft.com/library/de...ertificate.asp

My problem is still with C++ to VB translation as the existing resources are all in C++.

There is a question of how to load the library then how to getProcAdress and then how to change the select_Cert_Struct used to construct the dialog box displayed to show the certificates….

[COLOR=DarkGreen]''//+-----------------------------------------------------------------------
''----
''//
''// Microsoft Windows
''// Copyright (C) Microsoft Corporation, 1992 - 1997.
''//
''// File: cryptdlg.h
''//
''// Contents: Common Cryptographic Dialog API Prototypes and Definitions
''//
''//-----------------------------------------------------------------------
''-----
''
''#ifndef __CRYPTDLG_H__
''#define __CRYPTDLG_H__
''
''#if defined (_MSC_VER) && (_MSC_VER >= 1020)
''#pragma once
''#End If
''
''#ifdef _CRYPTDLG_
''#define CRYPTDLGAPI
''#Else
''#define CRYPTDLGAPI DECLSPEC_IMPORT
''#End If
''
''#if (_WIN32_WINNT >= 0x0400) || defined(_MAC) || defined(WIN16)
''
''#include <prsht.h>
''
''#ifdef __cplusplus
''extern "C" {
''#End If
''
''// Master flags to control how revocation is managed
''
''#define CRYTPDLG_FLAGS_MASK 0xff000000
''#define CRYPTDLG_REVOCATION_DEFAULT 0x00000000
''#define CRYPTDLG_REVOCATION_ONLINE 0x80000000
''#define CRYPTDLG_REVOCATION_CACHE 0x40000000
''#define CRYPTDLG_REVOCATION_NONE 0x20000000
''
''
''// Policy flags which control how we deal with user’s certificates
''
''#define CRYPTDLG_POLICY_MASK 0x0000FFFF
''#define POLICY_IGNORE_NON_CRITICAL_BC 0x00000001
''
''#define CRYPTDLG_ACTION_MASK 0xFFFF0000
''#define ACTION_REVOCATION_DEFAULT_ONLINE 0x00010000
''#define ACTION_REVOCATION_DEFAULT_CACHE 0x00020000
''
''//
''// Many of the common dialogs can be passed a filter proc to reduce
''// the set of certificates displayed. A generic filter proc has been
''// provided to cover many of the generic cases.
''// Return TRUE to display and FALSE to hide
''
''typedef BOOL (WINAPI * PFNCMFILTERPROC)(
''IN PCCERT_CONTEXT pCertContext,
''IN DWORD, // lCustData, a cookie
''IN DWORD, // dwFlags
''IN DWORD); // dwDisplayWell
''
''// Display Well Values
''#define CERT_DISPWELL_SELECT 1
''#define CERT_DISPWELL_TRUST_CA_CERT 2
''#define CERT_DISPWELL_TRUST_LEAF_CERT 3
''#define CERT_DISPWELL_TRUST_ADD_CA_CERT 4
''#define CERT_DISPWELL_TRUST_ADD_LEAF_CERT 5
''#define CERT_DISPWELL_DISTRUST_CA_CERT 6
''#define CERT_DISPWELL_DISTRUST_LEAF_CERT 7
''#define CERT_DISPWELL_DISTRUST_ADD_CA_CERT 8
''#define CERT_DISPWELL_DISTRUST_ADD_LEAF_CERT 9
''
''//
''typedef UINT (WINAPI * PFNCMHOOKPROC)(
''IN HWND hwndDialog,
''IN UINT message,
''IN WPARAM wParam,
''IN LPARAM lParam);
''
''//
''#define CSS_SELECTCERT_MASK 0x00ffffff
''#define CSS_HIDE_PROPERTIES 0x00000001
''#define CSS_ENABLEHOOK 0x00000002
''#define CSS_ALLOWMULTISELECT 0x00000004
''#define CSS_SHOW_HELP 0x00000010
''#define CSS_ENABLETEMPLATE 0x00000020
''#define CSS_ENABLETEMPLATEHANDLE 0x00000040
''
''#define SELCERT_OK IDOK
''#define SELCERT_CANCEL IDCANCEL
''#define SELCERT_PROPERTIES 100
''#define SELCERT_FINEPRINT 101
''#define SELCERT_CERTLIST 102
''#define SELCERT_HELP IDHELP
''#define SELCERT_ISSUED_TO 103
''#define SELCERT_VALIDITY 104
''#define SELCERT_ALGORITHM 105
''#define SELCERT_SERIAL_NUM 106
''#define SELCERT_THUMBPRINT 107
''
''typedef struct tagCSSA {
''DWORD dwSize;
''HWND hwndParent;
''HINSTANCE hInstance;
''LPCSTR pTemplateName;
''DWORD dwFlags;
''LPCSTR szTitle;
''DWORD cCertStore;
''HCERTSTORE * arrayCertStore;
''LPCSTR szPurposeOid;
''DWORD cCertContext;
''PCCERT_CONTEXT * arrayCertContext;
''DWORD lCustData;
''PFNCMHOOKPROC pfnHook;
''PFNCMFILTERPROC pfnFilter;
''LPCSTR szHelpFileName;
''DWORD dwHelpId;
''HCRYPTPROV hprov;
''} CERT_SELECT_STRUCT_A, *PCERT_SELECT_STRUCT_A;
''
''typedef struct tagCSSW {
''DWORD dwSize;
''HWND hwndParent;
''HINSTANCE hInstance;
''LPCWSTR pTemplateName;
''DWORD dwFlags;
''LPCWSTR szTitle;
''DWORD cCertStore;
''HCERTSTORE * arrayCertStore;
''LPCSTR szPurposeOid;
''DWORD cCertContext;
''PCCERT_CONTEXT * arrayCertContext;
''DWORD lCustData;
''PFNCMHOOKPROC pfnHook;
''PFNCMFILTERPROC pfnFilter;
''LPCWSTR szHelpFileName;
''DWORD dwHelpId;
''HCRYPTPROV hprov;
''} CERT_SELECT_STRUCT_W, *PCERT_SELECT_STRUCT_W;
''
''#ifdef UNICODE
''typedef CERT_SELECT_STRUCT_W CERT_SELECT_STRUCT;
''typedef PCERT_SELECT_STRUCT_W PCERT_SELECT_STRUCT;
''#Else
''typedef CERT_SELECT_STRUCT_A CERT_SELECT_STRUCT;
''typedef PCERT_SELECT_STRUCT_A PCERT_SELECT_STRUCT;
''#endif // UNICODE
''
''CRYPTDLGAPI
''BOOL
''WINAPI
''CertSelectCertificateA(
''IN OUT PCERT_SELECT_STRUCT_A pCertSelectInfo
'');
''#ifdef MAC
''#define CertSelectCertificate CertSelectCertificateA
''#else // !MAC
''CRYPTDLGAPI
''BOOL
''WINAPI
''CertSelectCertificateW(
''IN OUT PCERT_SELECT_STRUCT_W pCertSelectInfo
'');
''#ifdef UNICODE
''#define CertSelectCertificate CertSelectCertificateW
''#Else
''#define CertSelectCertificate CertSelectCertificateA
''#End If
''#endif // MAC
''
''/////////////////////////////////////////////////////////////
''
''#define CM_VIEWFLAGS_MASK 0x00ffffff
''#define CM_ENABLEHOOK 0x00000001
''#define CM_SHOW_HELP 0x00000002
''#define CM_SHOW_HELPICON 0x00000004
''#define CM_ENABLETEMPLATE 0x00000008
''#define CM_HIDE_ADVANCEPAGE 0x00000010
''#define CM_HIDE_TRUSTPAGE 0x00000020
''#define CM_NO_NAMECHANGE 0x00000040
''#define CM_NO_EDITTRUST 0x00000080
''#define CM_HIDE_DETAILPAGE 0x00000100
''#define CM_ADD_CERT_STORES 0x00000200
''#define CERTVIEW_CRYPTUI_LPARAM 0x00800000
''
''typedef struct tagCERT_VIEWPROPERTIES_STRUCT_A {
''DWORD dwSize;
''HWND hwndParent;
''HINSTANCE hInstance;
''DWORD dwFlags;
''LPCSTR szTitle;
''PCCERT_CONTEXT pCertContext;
''LPSTR * arrayPurposes;
''DWORD cArrayPurposes;
''DWORD cRootStores; // Count of Root Stores
''HCERTSTORE * rghstoreRoots; // Array of root stores
''DWORD cStores; // Count of other stores to search
''HCERTSTORE * rghstoreCAs; // Array of other stores to search
''DWORD cTrustStores; // Count of trust stores
''HCERTSTORE * rghstoreTrust; // Array of trust stores
''HCRYPTPROV hprov; // Provider to use for verification
''DWORD lCustData;
''DWORD dwPad;
''LPCSTR szHelpFileName;
''DWORD dwHelpId;
''DWORD nStartPage;
''DWORD cArrayPropSheetPages;
''PROPSHEETPAGE * arrayPropSheetPages;
''} CERT_VIEWPROPERTIES_STRUCT_A, *PCERT_VIEWPROPERTIES_STRUCT_A;
''
''typedef struct tagCERT_VIEWPROPERTIES_STRUCT_W {
''DWORD dwSize;
''HWND hwndParent;
''HINSTANCE hInstance;
''DWORD dwFlags;
''LPCWSTR szTitle;
''PCCERT_CONTEXT pCertContext;
''LPSTR * arrayPurposes;
''DWORD cArrayPurposes;
''DWORD cRootStores; // Count of Root Stores
''HCERTSTORE * rghstoreRoots; // Array of root stores
''DWORD cStores; // Count of other stores to search
''HCERTSTORE * rghstoreCAs; // Array of other stores to search
''DWORD cTrustStores; // Count of trust stores
''HCERTSTORE * rghstoreTrust; // Array of trust stores
''HCRYPTPROV hprov; // Provider to use for verification
''DWORD lCustData;
''DWORD dwPad;
''LPCWSTR szHelpFileName;
''DWORD dwHelpId;
''DWORD nStartPage;
''DWORD cArrayPropSheetPages;
''PROPSHEETPAGE * arrayPropSheetPages;
''} CERT_VIEWPROPERTIES_STRUCT_W, *PCERT_VIEWPROPERTIES_STRUCT_W;
''
''#ifdef UNICODE
''typedef CERT_VIEWPROPERTIES_STRUCT_W CERT_VIEWPROPERTIES_STRUCT;
''typedef PCERT_VIEWPROPERTIES_STRUCT_W PCERT_VIEWPROPERTIES_STRUCT;
''#Else
''typedef CERT_VIEWPROPERTIES_STRUCT_A CERT_VIEWPROPERTIES_STRUCT;
''typedef PCERT_VIEWPROPERTIES_STRUCT_A PCERT_VIEWPROPERTIES_STRUCT;
''#endif // UNICODE
''