703
社区成员
发帖
与我相关
我的任务
分享
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->ShowMainForm = false;
bool addedOK=false;
addedOK=RunExFile("dll1.dll","go");
if(addedOK)
{
Application->ShowMainForm = true;
}
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::RunExFile(char * dllname, char * user) // 外部扩充调用
{ /* 入口格式:调用dll文件名,传递用户名 */
bool OK;
if(FileExists(dllname))
{
boolean PrevValue = IsLibrary; //C++ Builder - Exception 'Need call dxFinalizeGDIPlus before free library!' when using DX components in a DLL
hInstance=LoadLibrary(dllname);
if(hInstance)
{
(FARPROC &) DllWin=GetProcAddress(hInstance,"DllWin");
if(DllWin)
{
OK=DllWin(user);
}
else
{
ShowMessage(" 不能找到函数入口,请重新安装本程序。");
}
}
else
{
ShowMessage("不能载入DLL文件,请重新安装本程序。");
}
FreeLibrary(hInstance);
IsLibrary = PrevValue; //C++ Builder - Exception 'Need call dxFinalizeGDIPlus before free library!' when using DX components in a DLL
}
else
{
ShowMessage(" 相应模块文件丢失,请重新安装本程序。");
}
return OK;
}
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
HINSTANCE hInstance;// DLL接口
bool __fastcall RunExFile(char * dllname, char * user); // 外部扩充调用
bool (_stdcall * DllWin)(char * user);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
extern "C" __declspec(dllexport) bool _stdcall DllWin(char * user)
{
TForm1 * frm=new TForm1(Application,user);
frm->ShowModal();
bool bb=frm->frmAdded;
delete frm; //这里被释放了
return bb;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
frmAdded=true;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit3.cpp", Form3);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
SetApplicationMainFormOnTaskBar(Application, true);
//在这里显示登入窗口,并判断返回,如果失败就直接return,退出程序
Application->CreateForm(__classid(TForm3), &Form3);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
#include <vcl.h>
#include <objbase.h>
#include <windows.h>
#include "Unit1.h"
#pragma hdrstop
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
if (reason == DLL_PROCESS_ATTACH)
{
CoInitialize(NULL);
}
else if(reason == DLL_PROCESS_DETACH)
{
CoUninitialize();
}
return 1;
}
//---------------------------------------------------------------------------
extern "C" __declspec(dllexport) bool _stdcall DllWin(char * user)
{
TForm1 * frm=new TForm1(Application,user);
frm->ShowModal();
delete frm;
return frm->frmAdded;
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner,char * user)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
frmAdded=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
frmAdded=true;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
TButton *Button3;
void __fastcall FormCreate(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner,char * user);
bool frmAdded;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif