15,471
社区成员
发帖
与我相关
我的任务
分享
library Smart;
uses
SysUtils,
Classes,
Forms,
Dialogs,
Windows,
SmartWord in 'SmartWord.pas' {frmSmartWord},
pub in 'pub.pas';
{$R *.res}
var
AppDLL:TApplication;
ScrDLL:TScreen;
//
procedure MyDLLProc(Reason:Integer);
begin
try
if Reason=DLL_PROCESS_DETACH then
begin
Application:=AppDLL;
Screen:=ScrDLL;
end;
except
on e:Exception do
begin
ShowMessage(e.Message);
end;
end;
end;
//function SmartWord(App:TApplication;Scr:TScreen;DoctorName,UserName:PChar):Boolean;stdcall;
function SmartWord(DoctorName,UserName:PChar):Boolean;stdcall;
begin
//Application:=App;
//ScrDLL:=Screen;
//showmessage(doctorname);
//showmessage(username);
sDoctorName:=DoctorName;
sUserName:=UserName;
if not Assigned(frmSmartWord) then
Application.CreateForm(TfrmSmartWord,frmSmartWord);
frmSmartWord.Show;
end;
exports
SmartWord;
begin
try
AppDLL:=Application;
ScrDLL:=Screen;
DLLProc:=@MyDLLProc;
except
on e:Exception do
ShowMessage(e.Message);
end;
end.
function SmartWord(DoctorName,UserName:PChar):Boolean;stdcall;external 'Smart.dll';
SmartWord(PChar('doc'),PChar('user'));
//调用dll
HINSTANCE hDll;
//FARPROC lpFunc;
hDll=LoadLibrary(LPCWSTR("Smart.DLL"));
CString strMsg ="失败";
if (!hDll)
{
AfxMessageBox(strMsg);
}
else
{
strMsg="成功";
AfxMessageBox();
}
hDll=LoadLibrary( _T("Smart.DLL") );
typedef int(*func)(const char*,const char*);
func SmartWord= (func)GetProcAddress( hDll , "SmartWord" );
SmartWord( "aaaaaa" , "b" );