?
Solved

Load DLL From Memory

Posted on 2005-05-01
7
Medium Priority
?
502 Views
Last Modified: 2010-04-05
I have an application in which I store numerous DLLs and currently save the DLLs to the temp folder then load them from there.

I would like to know if there is any way to load a DLL directly from memory. I have access to the DLL as a stream, is there any way I can load the DLL directly from there and use GetProcAddress on it, then call some methods and free it?

I'd really like to be able to avaoid saving to disk if its possible.
0
Comment
Question by:paulb1989
  • 3
  • 2
  • 2
7 Comments
 
LVL 34

Expert Comment

by:Slick812
ID: 13904612
hello  paulb1989, I do not get your reason for your methods? ? if your program has these DLLs in it's resources, then it seems like you should just add the code in the DLL's to your program, since all of the code (as the DLL) in in your program file anyway. Any reason for wanting to have the DLLs as resource and call them from a resource memory location? It may be posible to get the memory location of a DLL function (if it is static, as not in a TObject method),  However, there may be problems if your DLL has any inialization code that sets up non-static variables,
0
 
LVL 5

Author Comment

by:paulb1989
ID: 13904620
The reason is that I have a program that adds DLLs to the end of another EXE file (the one that loads them), so there may be different DLLs each time the program runs. Other DLLs may be developed and there may be any combination of DLLs attached to the EXE. I can read them into a TMemoryStream, and currently I save them to disk which I would like not to have to do...
0
 
LVL 34

Expert Comment

by:Slick812
ID: 13904689
OK, this seems more complex than I thought,
If a DLL has Static functions, I think you can get the memory address to use in a TResourceStream, It would be the same memory address the GetProcAddress( ) function returns, minus the hInstance of the DLL,

But I tried to tell you, there may be non-static variables used or reference data set up in the DLL during it's initialization, the initialization will NOT be executed

and there will be NO variable storage set up on the heap for the DLL global variables

this may cause big problems. .  
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Assisted Solution

by:Slick812
Slick812 earned 1000 total points
ID: 13904848
You might ask how to execute (run) a DLL from memory, I have seen this question asked here at EE and other question forums (the actuall questions were for programs not DLLs), and I have yet to see a way to do this, the win system has it's program execution based on a File location, so It may be very difficult to run an executable from just a memory location
0
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 1000 total points
ID: 13910716
the answer would be *no*, is not possible using documented functions, however it is possible, using (of course) undocumented functions or some hacks, the problem with that is that your code can break any time with a service pack or some update
0
 
LVL 5

Author Comment

by:paulb1989
ID: 13910991
OK it seems like I'll have to continue with the method I'm using (saving to disk).
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13927853
lot safer
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question