可以,用我这个
不用释放DLL到硬盘,直接在内存加载调用
下载地址:http://u.skygz.com/mypane.aspx?down=ok&filepath=skygz%2f%b2%fa%c6%b7%2f%b4%d3%c4%da%b4%e6%bc%d3%d4%d8DLL%b2%a2%b5%f7%d3%c3_%ba%af%ca%fd%bf%e2_FOR_Delphi_v1_0_0_1.rar
示例:
{$R MyDll.Res}
Uses
MemLibLoader;
Var
DllHandle: THandle;
MsgBox: Function(lpText, LpCaption: PAnsiChar): Integer; Stdcall;
MsgBoxEx: Function(lpText, LpCaption: PAnsiChar; UType: UINT): Integer; Stdcall;
Procedure TFrmMain.Cmd_ByNameClick(Sender: TObject);
Begin
If @MsgBox <> Nil Then
MsgBox('这是按名称调用的函数', '提示');
End;
Procedure TFrmMain.CmdByIndexClick(Sender: TObject);
Begin
If @MsgBoxEx <> Nil Then
MsgBoxEx('这是按序号调用的函数', '提示', MB_ICONINFORMATION Or MB_OKCANCEL);
End;
Procedure TFrmMain.SetControls(B: Boolean);
Begin
Cmd_Load.Enabled := Not B;
Cmd_Free.Enabled := B;
End;
Procedure TFrmMain.Cmd_LoadClick(Sender: TObject);
Var
FileName: String;
Mem: TMemoryStream;
FileArray: Array Of Byte;
Begin
SetControls(true);
FileName := ExtractFilePath(ParamStr(0)) + 'MyDll.Dll';
Case CBLoadType.ItemIndex Of
0: //内存
Begin
Mem := TMemoryStream.Create;
Mem.LoadFromFile(FileName);
DllHandle := _LoadLibraryMem(Mem.Memory);
Mem.Free;
End;
1: //数组
Begin
Mem := TMemoryStream.Create;
Mem.LoadFromFile(FileName);
SetLength(FileArray, Mem.Size);
Mem.ReadBuffer(FileArray[0], Mem.Size);
DllHandle := _LoadLibraryMem(FileArray);
Mem.Free;
End;
2: DllHandle := _LoadLibraryFromResourceA(HInstance, 'MyDLL', 'DLL'); //资源
3: DllHandle := _LoadLibraryA(PChar(FileName)); //文件
End;
If DllHandle <> 0 Then
Begin
@MsgBox := _GetProcAddress(DllHandle, 'MsgBox');
@MsgBoxEx := _GetProcAddress(DllHandle, MakeIntResource($1));
End Else SetControls(false);
End;
Procedure TFrmMain.Cmd_FreeClick(Sender: TObject);
Begin
SetControls(false);
@MsgBox := Nil;
@MsgBoxEx := Nil;
_FreeLibrary(DllHandle);
End;
Procedure TFrmMain.FormCreate(Sender: TObject);
Begin
CBLoadType.ItemIndex := 0;
End;