怎样给WebBrowser通过InternetSetOption选择证书

weixin_6550523 2008-10-07 10:33:59
用WebBrowser做的浏览器,想通过InternetSetOption来自动选择证书,问题是InternetSetOption的第一个参数HINTERNET上哪取呀?
...全文
378 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
WinEggDrop 2008-10-08
  • 打赏
  • 举报
回复
[Quote=引用楼主 thncuzl 的帖子:]
用WebBrowser做的浏览器,想通过InternetSetOption来自动选择证书,问题是InternetSetOption的第一个参数HINTERNET上哪取呀?
[/Quote]

本地设置,第一参数为NULL.
VsirSoft 2008-10-08
  • 打赏
  • 举报
回复
写0就可以.
weixin_6550523 2008-10-08
  • 打赏
  • 举报
回复
高手不现身?
weixin_6550523 2008-10-08
  • 打赏
  • 举报
回复
看样子我的思路错了?
weixin_6550523 2008-10-08
  • 打赏
  • 举报
回复
运行错误,错误码:
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE (INTERNET_ERROR_BASE + 18)
代码如下:
LPWSTR pswzFirstCert = L"sss";// Subject of the first
// certificate.
HCERTSTORE hSystemStore; // The system store handle
PCCERT_CONTEXT pDesiredCert;
pDesiredCert = NULL;

if(hSystemStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM, // The system store will be a
// virtual store.
0, // Encoding type not need with this PROV.
NULL, // Accept the default HCRYPTPROV.
CERT_SYSTEM_STORE_CURRENT_USER,
L"ROOT")) // System store name.//MY CA ROOT SPC 四种
{
printf("Opened the MY system store. \n");
}
else
{

}
//-------------------------------------------------------------------
// Get a certificate that has the string "Full Test Cert" in its subject.
if(pDesiredCert)
CertFreeCertificateContext(pDesiredCert);
if(pDesiredCert=CertFindCertificateInStore(
hSystemStore,
X509_ASN_ENCODING, // Use X509_ASN_ENCODING.
0, // No dwFlags needed.
CERT_FIND_SUBJECT_STR, // Find a certificate with a
// subject that matches the string
// in the next parameter.
pswzFirstCert, // The Unicode string to be found
// in a certificate's subject.
NULL)) // NULL is used so that the
// search will begin at the
// beginning of the certificate
// store.
{
printf("The %S certificate was found. \n",pswzFirstCert);
}
else
{
printf("The %S certificate was not found. \n",pswzFirstCert);
}

if(hSystemStore)
CertCloseStore(hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG);

if( InternetSetOption (0, INTERNET_OPTION_CLIENT_CERT_CONTEXT,
(LPVOID)pDesiredCert, sizeof (CERT_CONTEXT) ) == FALSE )
{
int i = GetLastError();

printf("InternetSetOption failed with error %d. \n",i);
}

if(pDesiredCert) CertFreeCertificateContext(pDesiredCert);

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧