Re: possibly capicom bug?
From: Dimitar Lazarov (lazarov_at_csoft.bg)
Date: 04/22/05
- Previous message: Rhett Gong [MSFT]: "RE: Find what SharePoint groups a user belongs to."
- In reply to: LY: "possibly capicom bug?"
- Next in thread: LY: "Re: possibly capicom bug?"
- Reply: LY: "Re: possibly capicom bug?"
- Reply: LY: "Re: possibly capicom bug?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 22 Apr 2005 11:21:52 +0300
I'm sure that it's not a bug. :-) What is the hr value when the export fail?
Dimitar
"LY" <LY@discussions.microsoft.com> wrote in message
news:33F85B55-EDE1-4F80-BD73-2FE1A5F40638@microsoft.com...
> what I want to do is retrive a certificate from MY store and then export
> it
> to local hard drive. I am using the store example in the redistributable
> packet for capicom 2.0.0.3 with the following changes:
>
>
> /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>
>
>
> THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
> KIND,
>
> EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
>
> WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
>
>
>
> Copyright (C) 1999 - 2000. Microsoft Corporation. All rights reserved.
>
>
>
> Module: Store.cpp
>
>
>
> Abstract: Main program of CAPICOM Store sample. See ReadMe.txt for more
>
> detail information about this sample.
>
>
>
> Environment: Win32 console, UNICODE ready.
>
>
>
> ------------------------------------------------------------------------------*/
>
>
>
> #include <tchar.h>
>
> #include <stdio.h>
>
> #include <atlbase.h>
>
> #include <windows.h>
>
>
>
> #pragma warning (disable : 4192)
>
>
>
> //
>
> // Import TLB from DLL
>
> //
>
> // Note: Make sure either you have the DLL in the current directory, or
> point
>
> // it to the correct directory on you drive.
>
> //
>
> #import "capicom.dll"
>
>
>
> //
>
> // Use CAPICOM namespace.
>
> //
>
> using namespace CAPICOM;
>
>
>
> /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>
> Module: main()
>
>
>
> Remark: Entry point of CAPICOM Store C++ sample.
>
>
>
> -----------------------------------------------------------------------------*/
>
>
>
> char filename[]="c:\\my.pfx";
>
> int __cdecl _tmain (int argc, _TCHAR * argv[])
>
> {
>
> HRESULT hr = S_OK;
>
>
>
> //
>
> // Initialize COM library.
>
> //
>
> CoInitialize(0);
>
>
>
> try
>
> {
>
> //
>
> // Open current user My store.
>
> //
>
> _bstr_t bstrName = _T("MY");
>
> IStorePtr pIStore(__uuidof(Store));
>
>
>
> if (FAILED(hr = pIStore->Open(CAPICOM_CURRENT_USER_STORE,
>
> bstrName,
>
> CAPICOM_STORE_OPEN_READ_ONLY)))
>
> {
>
> ATLTRACE(_T("Error [%#x]: pIStore->Open() failed at line
> %d.\n"), hr, __LINE__);
>
> throw hr;
>
> }
>
>
>
> //
>
> // Display all certificate in the store.
>
> //
>
> IUnknownPtr pIUnknown;
>
> IEnumVARIANTPtr pIEnum;
>
> _variant_t pDisp;
>
> ULONG ulFetched;
>
>
>
> //
>
> // Get _NewEnum of Certificates collection.
>
> //
>
> if (FAILED(hr = pIStore->Certificates->get__NewEnum(&pIUnknown)))
>
> {
>
> ATLTRACE(_T("Error [%#x]: pIStore->Certificates->get__NewEnum()
> failed at line
> %d.\n"), hr, __LINE__);
>
> throw hr;
>
> }
>
>
>
> //
>
> // Get IEnumVARIANT interface of _NewEnum.
>
> //
>
> if (FAILED(hr = pIUnknown->QueryInterface(IID_IEnumVARIANT, (void
> **) &pIEnum)))
>
> {
>
> ATLTRACE(_T("Error [%#x]: pIUnknown->QueryInterface() failed at
> line %d.\n"), hr,
> __LINE__);
>
> throw hr;
>
> }
>
>
>
> //
>
> // Now loop through all items in the collection.
>
> //
>
> while (pIEnum->Next(1, &pDisp, &ulFetched) == S_OK)
>
> {
>
> //
>
> // Display the certificate. This function is always ok on
> both version of windows!
>
> //
>
> if (FAILED(hr = ((ICertificatePtr) pDisp.pdispVal)->Display()))
>
> {
>
> ATLTRACE(_T("Error [%#x]: ((ICertificatePtr)
> pDisp.pdispVal)->Display() failed at
> line %d.\n"), hr, __LINE__);
>
> throw hr;
>
> }
>
>
>
> //export certificate to a pfx file always failed on an English
> version windows! May it a
> bug of capicom!
>
> if(FAILED(hr=((structICertificate2*)
> pDisp.pdispVal)->Save(_T(filename),_T("abcd"),CAPICOM_CERTIFICATE_SAVE_AS_PFX,CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY)))
>
> {
>
> ATLTRACE(_T("Error [%#x]: ((ICertificatePtr)
> pDisp.pdispVal)->Display() failed at
> line %d.\n"), hr, __LINE__);
>
> printf("save certificate to file failed!");
>
> throw hr;
>
> }
>
> pDisp.Clear();
>
> }
>
> }
>
>
>
> catch (_com_error e)
>
> {
>
> hr = e.Error();
>
> ATLTRACE(_T("Error [%#x]: %s.\n"), hr, e.ErrorMessage());
>
> printf("%s",e.ErrorMessage());
>
> }
>
>
>
> catch (HRESULT hr)
>
> {
>
> ATLTRACE(_T("Error [%#x]: CAPICOM error.\n"), hr);
>
> }
>
>
>
> catch(...)
>
> {
>
> hr = CAPICOM_E_UNKNOWN;
>
> ATLTRACE(_T("Unknown error.\n"));
>
> }
>
>
>
> CoUninitialize();
>
>
>
> return (int) hr;
>
> }
>
>
>
> The problem is that though it can work on an Chinese version of
> windows(2000,xp ,and 2003 server) ,it always failed in exporting the
> certificate in an English version windows. Can any one be of help? Thanks
> in
> advance!
- Previous message: Rhett Gong [MSFT]: "RE: Find what SharePoint groups a user belongs to."
- In reply to: LY: "possibly capicom bug?"
- Next in thread: LY: "Re: possibly capicom bug?"
- Reply: LY: "Re: possibly capicom bug?"
- Reply: LY: "Re: possibly capicom bug?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|