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

类别:VC语言 点击:0 评论:0 推荐:

在程序中注册ActiveX控件(.OCX)的函数

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"));   //获取注册函数DllRegisterServer地址

 

         if(lpDllEntryPoint!=NULL)   //调用注册函数DllRegisterServer

         {

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

                   {

                            FreeLibrary(hLib);

                            return FALSE ;

                    }

                   return TRUE ;

         }

         else

                   return FALSE ;

}

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

在程序中注销ActiveX控件(.OCX)的函数

 

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"));        //获取注册函数DllUnregisterServer地址

 

         if(lpDllEntryPoint!=NULL)   //调用注册函数DllUnregisterServer

         {

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

                   {

                            FreeLibrary(hLib);

                            return FALSE ;

                    }

                   return TRUE ;

         }

         else

                   return FALSE ;

}

本文地址:http://com.8s8s.com/it/it2713.htm