明辉手游网中心:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

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

[摘要]在程序中注册ActiveX控件(.OCX)的函数BOOL RegisterOcx(LPCTSTR OcxFileName) LPCTSTR pszDllName = OcxFileName ; //ActiveX控件的路径及文件名 ...
在程序中注册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 ;

}