明辉站/网站教程/内容

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

网站教程2024-06-15 阅读
[摘要]在程序中注册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 ;

}

……

相关阅读