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

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit2.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. HINSTANCE hComm;
  10. void __stdcall (*OpenMyForm)(HWND);
  11. void __stdcall (*CloseMyForm)(void);
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14.         : TForm(Owner)
  15. {
  16.   hComm=LoadLibrary("MyForm.dll");
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TForm1::Button1Click(TObject *Sender)
  20. {
  21.   FARPROC lpFarProc;
  22.   if(hComm!=NULL)
  23.   {
  24.     lpFarProc = GetProcAddress(hComm,"OpenMyForm");
  25.     if(lpFarProc==NULL)
  26.       ShowMessage("func Error");
  27.     else
  28.     {
  29.       OpenMyForm = (void __stdcall (__cdecl*)(HWND))lpFarProc; //指针类型转换
  30.       OpenMyForm(Application->Handle);
  31.     }
  32.   }
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::FormDestroy(TObject *Sender)
  36. {
  37.   FreeLibrary(hComm);
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TForm1::Button2Click(TObject *Sender)
  41. {
  42.   FARPROC lpFarProc;
  43.   if(hComm!=NULL)
  44.   {
  45.     lpFarProc = GetProcAddress(hComm,"CloseMyForm");
  46.     if(lpFarProc==NULL)
  47.       ShowMessage("func Error");
  48.     else
  49.     {
  50.       CloseMyForm = (void __stdcall (__cdecl*)(void))lpFarProc; //指针类型转换
  51.       CloseMyForm();
  52.     }
  53.   }
  54. }
  55. //---------------------------------------------------------------------------