编译完成的ActiveX控件可以使用DllRegisterServer来完成自动注册,
注册代码:
- void CRegisterServerDlg::OnBnClickedBtnRegister()
- {
- // TODO: 在此添加控件通知处理程序代码
- CString strLib;
- GetDlgItemText(IDC_EDIT1, strLib);
- HMODULE hLib = ::LoadLibrary(strLib);
- if(hLib == 0) {
- strLib.Format(L"LoadLibrary failed:%d", GetLastError());
- SetDlgItemText(IDC_STC_STATUS, strLib);
- return ;
- }
- HRESULT (STDAPICALLTYPE *pDllRegisterServer)();
- (FARPROC&)pDllRegisterServer = ::GetProcAddress(hLib, _T("DllRegisterServer"));
- if(pDllRegisterServer == NULL) {
- strLib.Format(L"GetProcAddress DllRegisterServer failed:%d", GetLastError());
- SetDlgItemText(IDC_STC_STATUS, strLib);
- ::FreeLibrary(hLib);
- return ;
- }
- if(FAILED(pDllRegisterServer ())) {
- strLib.Format(L"DllRegisterServer failed:%d", GetLastError());
- SetDlgItemText(IDC_STC_STATUS, strLib);
- ::FreeLibrary(hLib);
- } else {
- ::FreeLibrary(hLib);
- SetDlgItemText(IDC_STC_STATUS, L"DllRegisterServer Success!!");
- }
- }
卸载控件:
- void CRegisterServerDlg::OnBnClickedBtnUnregister()
- {
- // TODO: 在此添加控件通知处理程序代码
- CString strLib;
- GetDlgItemText(IDC_EDIT1, strLib);
- HMODULE hLib = ::LoadLibrary(strLib);
- if(hLib == 0) {
- SetDlgItemText(IDC_STC_STATUS, L"LoadLibrary failed!!!");
- }
- HRESULT (STDAPICALLTYPE *pDllUnregisterServer)();
- (FARPROC&)pDllUnregisterServer = ::GetProcAddress(hLib, _T("DllUnregisterServer"));
- if(pDllUnregisterServer == NULL) {
- ::FreeLibrary(hLib);
- SetDlgItemText(IDC_STC_STATUS, L"GetProcAddress DllUnregisterServer failed!!");
- }
- if(FAILED(pDllUnregisterServer ())) {
- ::FreeLibrary(hLib);
- SetDlgItemText(IDC_STC_STATUS, L"DllUnregisterServer failed!!");
- } else {
- ::FreeLibrary(hLib);
- SetDlgItemText(IDC_STC_STATUS, L"DllUnregisterServer Success!!");
- }
- }
写了一个MFC的自动注册软件
RegisterServer.rar
阅读(1331) | 评论(0) | 转发(1) |