http://blog.csdn.net/luheng2006/archive/2010/08/19/5824399.aspx
注冊(cè)O(shè)CX控件
BOOL CYourClass::RegistOcx()
{
HINSTANCE hLib = LoadLibrary("NTGraph.ocx"); //指定要注冊(cè)的ocx文件的路徑及文件名。 if (hLib == NULL) { MessageBox("不能載入OCX文件!"); return; }
//獲取注冊(cè)函數(shù)DllRegisterServer地址 FARPROC lpDllEntryPoint; lpDllEntryPoint = GetProcAddress(hLib,"DllRegisterServer");
//調(diào)用注冊(cè)函數(shù)DllRegisterServer if(lpDllEntryPoint!=NULL) { if(FAILED((*lpDllEntryPoint)())) { //MessageBox(Handle,"調(diào)用DllRegisterServer失敗!","失敗ing..",MB_OK); MessageBox("OCX注冊(cè)失敗!"); FreeLibrary(hLib); return; }; //MessageBox(Handle,"注冊(cè)成功!","Reg",MB_OK); MessageBox("OCX注冊(cè)成功!"); } else MessageBox("OCX注冊(cè)失敗!"); //MessageBox(Handle,"調(diào)用DllRegisterServer失敗!","失敗ing..",MB_OK);
}
卸載控件
BOOL CYourClass::UnRegistOcx()
{
HINSTANCE hLib = LoadLibrary("NTGraph.ocx"); //指定要注冊(cè)的ocx文件的路徑及文件名。 if (hLib==NULL) { //MessageBox(Handle,"不能載入Dll文件!","失敗ing..",MB_OK); MessageBox("不能載入OCX文件!"); return; }
//獲取注冊(cè)函數(shù)DllRegisterServer地址 FARPROC lpDllEntryPoint; lpDllEntryPoint = GetProcAddress(hLib,"DllUnregisterServer");//注意這里是DllUnregisterServer。
//調(diào)用注冊(cè)函數(shù)DllRegisterServer if(lpDllEntryPoint!=NULL) { if(((*lpDllEntryPoint)())) { //MessageBox(Handle,"調(diào)用DllUnRegisterServer失??!","失敗ing..",MB_OK); MessageBox("調(diào)用DllUnRegisterServer失敗!!!"); FreeLibrary(hLib); return; }; //MessageBox(Handle,"注銷成功!","Unreg",MB_OK); MessageBox("OCX注銷成功!"); } else //MessageBox(Handle,"調(diào)用DllUnRegisterServer失敗!!!","結(jié)果",MB_OK); MessageBox("OCX調(diào)用DllUnRegisterServer失敗!!!");
}
判斷是否注冊(cè)
BOOL CYourClass::IsRegistOcx()
{ HKEY hKey; BOOL bPresent; TCHAR szPath[_MAX_PATH]; DWORD dwRegType; DWORD cbData = sizeof szPath * sizeof TCHAR;
if(RegOpenKeyEx(HKEY_CLASSES_ROOT,"ActiveX.ActiveXControl\\Clsid",0,KEY_READ,&hKey)!=ERROR_SUCCESS) return false; else return true; //ActiveX.ActiveXControl為控件的名稱和內(nèi)部名稱 如"NTGRAPH.NTGraphCtrl.1\\CLSID"
}
相關(guān):VC++ 注冊(cè)與卸載OCX控件的小工具源程序
下載: 1. http://www./user/looooooooong/file/3913386 2. http://www./soft/8071.shtml
(#)
|