Unit2.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit2.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- HINSTANCE hComm;
- void __stdcall (*OpenMyForm)(HWND);
- void __stdcall (*CloseMyForm)(void);
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- hComm=LoadLibrary("MyForm.dll");
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- FARPROC lpFarProc;
- if(hComm!=NULL)
- {
- lpFarProc = GetProcAddress(hComm,"OpenMyForm");
- if(lpFarProc==NULL)
- ShowMessage("func Error");
- else
- {
- OpenMyForm = (void __stdcall (__cdecl*)(HWND))lpFarProc; //指针类型转换
- OpenMyForm(Application->Handle);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormDestroy(TObject *Sender)
- {
- FreeLibrary(hComm);
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- FARPROC lpFarProc;
- if(hComm!=NULL)
- {
- lpFarProc = GetProcAddress(hComm,"CloseMyForm");
- if(lpFarProc==NULL)
- ShowMessage("func Error");
- else
- {
- CloseMyForm = (void __stdcall (__cdecl*)(void))lpFarProc; //指针类型转换
- CloseMyForm();
- }
- }
- }
- //---------------------------------------------------------------------------