Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- int __stdcall (*mycalc)(int,int);
- int __stdcall (*myfunc)(int,int);
- void __stdcall (*myte)(void);
- HINSTANCE hComm;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- hComm=LoadLibrary("MyDll.dll");
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- int nn;
- FARPROC lpFarProc;
- if(hComm!=NULL)
- {
- //
- lpFarProc = GetProcAddress(hComm,"myfunc");
- if(lpFarProc==NULL)
- ShowMessage("myfunc Error");
- else
- {
- myfunc = (int __stdcall (__cdecl*)(int, int))lpFarProc; //指针类型转换
- nn=myfunc(12,10);
- Edit1->Text=IntToStr(nn);
- }
- lpFarProc = GetProcAddress(hComm,"mycalc");
- if(lpFarProc==NULL)
- ShowMessage("mycalc Error");
- else
- {
- mycalc = (int __stdcall (__cdecl*)(int, int))lpFarProc; //指针类型转换
- nn=mycalc(12,10);
- Edit2->Text=IntToStr(nn);
- }
- //
- lpFarProc = GetProcAddress(hComm,"myte");
- if(lpFarProc==NULL)
- ShowMessage("FarProc Error");
- else
- {
- myte = (void __stdcall (__cdecl*)(void))lpFarProc; //指针类型转换
- myte();
- }
- }
- else
- ShowMessage("lib Error");
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormDestroy(TObject *Sender)
- {
- FreeLibrary(hComm);
- }
- //---------------------------------------------------------------------------