小
小雨哥
Unregistered / Unconfirmed
GUEST, unregistred user!
同样的,那二个辅助函数也需要修改一下:implementation{$R *.dfm}{$R csdll.res}var ShowDemo : function (Number: integer): integer; stdcall = nil;/// 全局的资源DLL模块变量var g_dll_module: Cardinal;/// 1)这个函数把res资源里的dll加载到程序里function LoadDLLFromResource(const ResourceName: AnsiString): Cardinal;var ms: TMemoryStream; rs: TResourceStream;begin ms := TMemoryStream.Create; try rs := TResourceStream.Create(HInstance, ResourceName, 'CDATA'); try ms.CopyFrom(rs, 0); ms.Position := 0; finally rs.Free; end; Result := LoadPE(ms.Memory, ms.Size); finally ms.Free; end;end;/// 2)这个函数把这个dll里的函数取出来function GetAddrFromMemoryDll(dll_module:Cardinal; const Name: AnsiString)ointer;begin try Result := GetProcAddressPE(dll_module, PAnsiChar(Name)); except Result := nil; end;end;procedure TForm1.Button1Click(Sender: TObject);var Number: integer;begin Number := 0; g_dll_module := LoadDLLFromResource('CSDLL'); if g_dll_module <> 0 then begin @ShowDemo := GetAddrFromMemoryDll(g_dll_module, 'Addtwo'); if @ShowDemo <> nil then Number := ShowDemo(100); end; Caption := IntToStr(Number);end;end.