久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

Delphi從應(yīng)用程序資源中直接執(zhí)行dll(不用先把dll存到磁盤上)

 quasiceo 2016-11-08
2011-11-08 08:38 1202人閱讀 評論(0) 收藏 舉報
分類:

目錄(?)[+]

http://www./go/f/86025?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+delphifeeds+%28DelphiFeeds.com%29

BTMemoryModule下載地址:http://code.google.com/p/memorymodule/downloads/list

Load a DLL From a Resource Directly From Memory in Delphi Applications

Use DLL from Resources (RES) Without Storing it on the Hard-Disk First

By , About.com Guide

Article idea by Mark E. Moss

The article how to store a DLL inside a Delphi program exe file as a resource explains how to ship a DLL with your Delphi application executable file as a resource.

Dynamic link libraries contain sharable code or resources, they provide the ability for multiple applications to share a single copy of a routine (or resource) they have in common.

Using resource (.RES) files, you can embed (and use) sound files, video clips, animations and more generally any kind of binary files in a Delphi executable.

Loading DLLs From Memory

Recently, I've received an email from Mark E. Moss, asking if a DLL stored in a RES can be used without first saving it on the file system (hard disk).

According to the article Loading a DLL from memory by Joachim Bauch, this is possible.

Here's how Joachim looks at the issue: The default windows API functions to load external libraries into a program (LoadLibrary, LoadLibraryEx) only work with files on the filesystem. It's therefore impossible to load a DLL from memory. But sometimes, you need exactly this functionality (e.g. you don't want to distribute a lot of files or want to make disassembling harder). Common workarounds for this problems are to write the DLL into a temporary file first and import it from there. When the program terminates, the temporary file gets deleted.

The code in the mentioned article is C++, the next step was to convert it to Delphi. Luckily, this has already been done by Martin Offenwanger (the author of DSPlayer).

Memory Module by Martin Offenwanger is an extended Delphi (and also Lazarus) compatible version of Joachim Bauch's C++ Memory Module 0.0.1. The zip package includes the complete Delphi source code of the MemoyModule (BTMemoryModule.pas). Furthermore there's a Delphi and sample included to demonstrate how to use it.

Loading DLLs From Resources From Memory

What was left to implement is to grab the DLL from a RES file and then call its procedures and functions.

If a demo DLL is stored as a resource using the RC file:

DemoDLL RCDATA DemoDLL.dll
to load it from the resource, the next code can be used:
var
  ms : TMemoryStream;
  rs : TResourceStream;
begin
  if
 0 <> FindResource(hInstance, 'DemoDLL', RT_RCDATA) then
  begin

    rs := TResourceStream.Create(hInstance, 'DemoDLL', RT_RCDATA);
    ms := TMemoryStream.Create;
    try
      ms.LoadFromStream(rs);

      ms.Position := 0;
      m_DllDataSize := ms.Size;
      mp_DllData := GetMemory(m_DllDataSize);

      ms.Read(mp_DllData^, m_DllDataSize);
    finally
      ms.Free;
      rs.Free;
    end;
  end;
end;
Next, when you have the DLL loaded from a resource into memory, you can call its procedures:
var
  btMM: PBTMemoryModule;
begin
  btMM := BTMemoryLoadLibary(mp_DllData, m_DllDataSize);
  try
    if btMM = nil then Abort;
    @m_TestCallstd := BTMemoryGetProcAddress(btMM, 'TestCallstd');
    if @m_TestCallstd = nil then Abort;
    m_TestCallstd('This is a Dll Memory call!');
  except
    Showmessage('An error occoured while loading the dll: ' + BTMemoryGetLastError);
  end;
  if Assigned(btMM) then BTMemoryFreeLibrary(btMM);
end;
That's it. Here's a quick recipe:
  1. Have / Create a DLL
  2. Store the DLL in a RES file
  3. Have BTMemoryModule implementation.
  4. Grab the DLL from the resource and load it directly into memory.
  5. Use BTMemoryModule methods to execute procedure from the DLL in memory.

BTMemoryLoadLibary in Delphi 2009, 2010, ...

Soon after publishing this article I've received an email from Jason Penny:
"The linked BTMemoryModule.pas does not work with Delphi 2009 (and I would assume Delphi 2010 also). 
I found a similar version of the BTMemoryModule.pas file a while ago, and made changes so it works with (at least) Delphi 2006, 2007 and 2009. My updated BTMemoryModule.pas, and a sample project, are at BTMemoryLoadLibary for Delphi >= 2009"
0
0

參考知識庫

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點,。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多