一个简单的例子:
type
mbf = function(hWnd: HWND; lpText, lpCaption: PChar; uType: UINT): Integer;
stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
h: integer;
mb: pointer;
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
ms.LoadFromFile('f:\user32.dll');
h := memLoadLibrary(ms.Memory);
if h > 0 then
begin
mb := memGetProcAddress(h, 'MessageBoxA');
if mb <> nil then
mbf(mb)(handle, 'test', 'test', mb_ok);
end;
memFreeLibrary(h);
ms.Free;
end;
代码未经测试,只是转载备用。