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

长平狐 发布于 2013/01/06 11:24
阅读 550
收藏 0

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

VC++    2009-07-29 22:25   阅读83   评论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://wmnmtm.blog.163.com/blog/static/382457142009629102522273/


原文链接:http://blog.csdn.net/sunboy_2050/article/details/4991290
加载中
返回顶部
顶部