Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. bool __fastcall TForm1::RegistOcx(AnsiString ocxname)
  16. {
  17.   HINSTANCE hLib = LoadLibrary(ocxname.c_str());
  18.   FARPROC lpDllEntryPoint;
  19.   if (hLib < (HINSTANCE)HINSTANCE_ERROR)
  20.   {
  21.     return False;
  22.   }
  23.   lpDllEntryPoint = GetProcAddress(hLib,"DllRegisterServer");
  24.   if(lpDllEntryPoint!=NULL)
  25.   {
  26.     if(FAILED((*lpDllEntryPoint)()))
  27.     {
  28.       ShowMessage("调用DllRegisterServer失败");
  29.       FreeLibrary(hLib);
  30.       return False;
  31.     };
  32.     ShowMessage("注 册 成 功");
  33.     return True;
  34.   }
  35.   else
  36.   {
  37.     ShowMessage("调用DllRegisterServer 失 败 !");
  38.     return False;
  39.   }
  40. }
  41. //---------------------------------------------------------------------------
  42. bool __fastcall TForm1::UnRegistOcx(AnsiString ocxname)
  43. {
  44.   HINSTANCE hLib = LoadLibrary(ocxname.c_str());
  45.   FARPROC lpDllEntryPoint;
  46.   if (hLib < (HINSTANCE)HINSTANCE_ERROR)
  47.   {
  48.     return False;
  49.   }
  50.   lpDllEntryPoint = GetProcAddress(hLib,"DllUnregisterServer");
  51.   if(lpDllEntryPoint!=NULL)
  52.   {
  53.     if(FAILED((*lpDllEntryPoint)()))
  54.     {
  55.       ShowMessage("调用DllUnregisterServer失败");
  56.       FreeLibrary(hLib);
  57.       return False;
  58.     };
  59.     ShowMessage("反 注 册 成 功");
  60.     return True;
  61.   }
  62.   else
  63.   {
  64.     ShowMessage("调用DllUnregisterServer 失 败 !");
  65.     return False;
  66.   }
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::Button1Click(TObject *Sender)
  70. {
  71.   RegistOcx("VCF132.ocx");
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TForm1::Button2Click(TObject *Sender)
  75. {
  76.   UnRegistOcx("VCF132.ocx");
  77. }
  78. //---------------------------------------------------------------------------