【嵌入式WinCE平台B/S应用】为嵌入式IE注册ActiveX控件。

时间:2021-10-08 09:37:02
编译完成的ActiveX控件可以使用DllRegisterServer来完成自动注册,
 
注册代码:

点击(此处)折叠或打开

  1. void CRegisterServerDlg::OnBnClickedBtnRegister()
  2. {
  3.     // TODO: 在此添加控件通知处理程序代码
  4.     CString strLib;
  5.     GetDlgItemText(IDC_EDIT1, strLib);
  6.     HMODULE hLib = ::LoadLibrary(strLib);
  7.     if(hLib == 0) {
  8.         strLib.Format(L"LoadLibrary failed:%d", GetLastError());
  9.         SetDlgItemText(IDC_STC_STATUS, strLib);
  10.         return ;
  11.     }
  12.     HRESULT (STDAPICALLTYPE *pDllRegisterServer)();
  13.     (FARPROC&)pDllRegisterServer = ::GetProcAddress(hLib, _T("DllRegisterServer"));
  14.     if(pDllRegisterServer == NULL) {
  15.         strLib.Format(L"GetProcAddress DllRegisterServer failed:%d", GetLastError());
  16.         SetDlgItemText(IDC_STC_STATUS, strLib);
  17.         ::FreeLibrary(hLib);
  18.         return ;
  19.     }
  20.     if(FAILED(pDllRegisterServer ())) {
  21.         strLib.Format(L"DllRegisterServer failed:%d", GetLastError());
  22.         SetDlgItemText(IDC_STC_STATUS, strLib);
  23.         ::FreeLibrary(hLib);
  24.     } else {
  25.         ::FreeLibrary(hLib);
  26.         SetDlgItemText(IDC_STC_STATUS, L"DllRegisterServer Success!!");
  27.     }

  28. }

 

卸载控件:

点击(此处)折叠或打开

  1. void CRegisterServerDlg::OnBnClickedBtnUnregister()
  2. {
  3.     // TODO: 在此添加控件通知处理程序代码
  4.     CString strLib;
  5.     GetDlgItemText(IDC_EDIT1, strLib);

  6.     HMODULE hLib = ::LoadLibrary(strLib);
  7.     if(hLib == 0) {
  8.         SetDlgItemText(IDC_STC_STATUS, L"LoadLibrary failed!!!");
  9.     }
  10.     HRESULT (STDAPICALLTYPE *pDllUnregisterServer)();
  11.     (FARPROC&)pDllUnregisterServer = ::GetProcAddress(hLib, _T("DllUnregisterServer"));
  12.     if(pDllUnregisterServer == NULL) {
  13.         ::FreeLibrary(hLib);
  14.         SetDlgItemText(IDC_STC_STATUS, L"GetProcAddress DllUnregisterServer failed!!");
  15.     }
  16.     if(FAILED(pDllUnregisterServer ())) {
  17.         ::FreeLibrary(hLib);
  18.         SetDlgItemText(IDC_STC_STATUS, L"DllUnregisterServer failed!!");
  19.     } else {
  20.         ::FreeLibrary(hLib);
  21.         SetDlgItemText(IDC_STC_STATUS, L"DllUnregisterServer Success!!");
  22.     }
  23. }

 

写了一个MFC的自动注册软件
【嵌入式WinCE平台B/S应用】为嵌入式IE注册ActiveX控件。 RegisterServer.rar


阅读(424) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~
评论热议