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 ;}