Install the certificate to the specified CSP by VC

Source: Internet
Author: User

Install the certificate to the specified CSP by VC, which supports win7 and Windows server2008 R2 64bit

Ulong installresponse_certenrolldll (maid) {int nret = 0; BSTR bstrcert = NULL; BSTR bstrpassword = NULL; hresult hr; ix509enrollment * penroll = NULL; iid clsid; IID riid; // obtain certificate information bstrcert = sysallocstring (strcert); bstrpassword = sysallocstring (_ T (""); // initialize comhr = coinitializeex (null, coinit_apartmentthreaded ); // coinit_apartmentthreaded); If (failed (HR) {nret = 6; // 6 failed to call the COM component coinitializeex goto error ;} // obtain the class ID and iidclsid =__ uuidof (cx509enrollment); riid = _ uuidof (ix509enrollment); HR = cocreateinstance (CLSID, null, clsctx_inproc_server, riid, (void **) & penroll); If (failed (HR) {nret = 7; // 7 call cocreateinstance failed goto error ;} hR = penroll-> initialize (contextuser); If (failed (HR) {nret = 8; // enroll initialize call failure goto error ;} hR = penroll-> installresponse (allownone, // installresponserestrictionflags. allownone, bstrcert, xcn_crypt_string_any, // 7 // encodingtype. xcn_crypt_string_any, "" bstrpassword); If (failed (HR) {nret = 9; // 9 enroll installresponse interface call failure goto error;} error: // clean up resources, etc. if (bstrcert) sysfreestring (bstrcert); If (bstrpassword) sysfreestring (bstrpassword); If (penroll) penroll-> release (); couninitialize (); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.