明輝手游網(wǎng)中心:是一個免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

在MFC程序中如何注冊/注銷ActiveX控件(.OCX)

[摘要]在程序中注冊ActiveX控件(.OCX)的函數(shù)BOOL RegisterOcx(LPCTSTR OcxFileName) LPCTSTR pszDllName = OcxFileName ; //ActiveX控件的路徑及文件名 ...
在程序中注冊ActiveX控件(.OCX)的函數(shù)

BOOL RegisterOcx(LPCTSTR OcxFileName)

{

         LPCTSTR pszDllName = OcxFileName ;         //ActiveX控件的路徑及文件名         

         HINSTANCE hLib = LoadLibrary(pszDllName); //裝載ActiveX控件

         if (hLib < (HINSTANCE)HINSTANCE_ERROR)

         {

                   return FALSE ;

         }

         FARPROC lpDllEntryPoint;

         lpDllEntryPoint = GetProcAddress(hLib,_T("DllRegisterServer"));   //獲取注冊函數(shù)DllRegisterServer地址



         if(lpDllEntryPoint!=NULL)   //調(diào)用注冊函數(shù)DllRegisterServer

         {

                  if(FAILED((*lpDllEntryPoint)()))

                   {

                            FreeLibrary(hLib);

                            return FALSE ;

                    }

                   return TRUE ;

         }

         else

                   return FALSE ;

}

//----------------------------------

在程序中注銷ActiveX控件(.OCX)的函數(shù)



BOOL UnRegisterOcx(LPCTSTR OcxFileName)

{

         LPCTSTR pszDllName = OcxFileName ;         //ActiveX控件的路徑及文件名         

         HINSTANCE hLib = LoadLibrary(pszDllName); //裝載ActiveX控件

         if (hLib < (HINSTANCE)HINSTANCE_ERROR)

         {

                   return FALSE ;

         }

         FARPROC lpDllEntryPoint;

         lpDllEntryPoint = GetProcAddress(hLib,_T("DllUnregisterServer"));        //獲取注冊函數(shù)DllUnregisterServer地址



         if(lpDllEntryPoint!=NULL)   //調(diào)用注冊函數(shù)DllUnregisterServer

         {

                  if(FAILED((*lpDllEntryPoint)()))

                   {

                            FreeLibrary(hLib);

                            return FALSE ;

                    }

                   return TRUE ;

         }

         else

                   return FALSE ;

}