473,770 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading an application (with .DLLs) into memory for later use

I have a C++ app on my flash drive that i am running, but often times,
i must take the flash drive out of the computer and use it elsewhere
while the executable continues to run.

however, the executable's behavior is sporadic, and it will
disappear. I think the app is calling a DLL that exists in the
current directory, but since the flash drive is gone, it can't find
it.

so, i wanted to know if i could load the executable with all of its
associated DLLs into memory and run it from there... that way i am
free to remove the flash drive at will.

*** DISCLAIMER *** i know that i could put the executable and
associated files on the local drive, please don't suggest alternatives
to my process. i want to load the program in memory and make sure it
can run it stably from there as a proof of concept.. just to prove
it's possible. so, if you are going to leave comments such as "why
are you doing this?" or "why dont you put it on the local drive?",
please save your effort.
Thanks to anyone willing to help me!!

Jul 30 '08 #1
1 1496
da**********@gm ail.com wrote:
I have a C++ app on my flash drive that i am running,
So why are you posting to a .NET group?

OK, I can't immediately think of an appropriate newsgroup off the top of my
head either, but I'm sure there is one (maybe one of the
comp.os.ms-windows.* groups). Anyway, moving right along...
but often times, i must take the flash drive out of the computer and use
it elsewhere while the executable continues to run.

however, the executable's behavior is sporadic, and it will
disappear. I think the app is calling a DLL that exists in the
current directory, but since the flash drive is gone, it can't find
it.

so, i wanted to know if i could load the executable with all of its
associated DLLs into memory and run it from there... that way i am
free to remove the flash drive at will.
I'm pretty sure this just isn't possible without the application cooperating
by copying itself to a safe location first, and restarting itself from
there. As I've always learned it, loaded binaries are just memory-mapped
files, which means that Windows can choose to discard pages (or never load
them in the first place) and page them in as needed. If you remove the
original file while it's still being used this way, things fail rather
spectacularly. I don't know whether the loader can detect executables being
launched from removable drives to take special action (like paging
everything out to swap, or not discarding any pages ever), but I'd assume it
doesn't, certainly not on all versions of Windows. If anyone knows
differently I'd love to hear it...

Paging can happen even if the application imports no further DLLs.
Obviously, if it does import DLLs this just exacerbates the problem, and if
it dynamically loads DLLs when they're no longer there you're completely
sunk. You can inject threads in the application and force it to load those
DLLs before its time, but this may cause DLL initialization to happen at an
unexpected time and it will prevent the DLL from unloading when the
application might expect it to, either of which can easily cause trouble.

That's assuming that you can figure out what DLLs it's going to dynamically
load in the first place -- the application might try discovering them on
disk, which will of course fail if the medium's gone. None of this will do
anything to safeguard against the possibility of the DLL needing to be
available for paging, and I haven't even addressed the problem of the
application's default directory becoming invalid (which is something a lot
of applications don't like, unsurprisingly) .

In short, the only reliable way of making this work is to copy the
executable and its dependencies to temporary (but reliable) storage.
*** DISCLAIMER *** i know that i could put the executable and
associated files on the local drive, please don't suggest alternatives
to my process. i want to load the program in memory and make sure it
can run it stably from there as a proof of concept.. just to prove
it's possible.
I'm not sure it is. You could try attaching a debugger to the application to
see why it *really* crashes (is it a page fault, a file not found error or
something else entirely?) and you might improve your chances by having the
executable and its dependencies be as small as possible (to encourage
everything being paged in and nothing being discarded) but it's still a
crapshoot.

You could try creating a RAM drive and copying the flash drive contents
there. That's technically still a "local drive", but it doesn't take up disk
space other than in the swap file.

--
J.
Jul 30 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1795
by: Nick Malik | last post by:
reposting to a wider audience "Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message news:WYONc.203854$XM6.119642@attbi_s53... > My turn to ask a question > > I am working on a plug-in for Sharepoint that will allow a developer to add > workflow rules. One of the rules will inform the adapter that it should > load a DLL that the developer writes, find a method that matches a
4
1431
by: Nick Malik | last post by:
My turn to ask a question I am working on a plug-in for Sharepoint that will allow a developer to add workflow rules. One of the rules will inform the adapter that it should load a DLL that the developer writes, find a method that matches a particular interface, and call it. I know, in general, I should be looking at the reflection classes. Does anyone have any design advice for me, or good working examples that would serve as a...
9
4493
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the "Let Users Add Functionality to Your .NET Applications with Macros and Plug-Ins" article at MSDN for the dynamic loading of DLLs http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
7
1694
by: Staale L. Hansen | last post by:
We have an application which uses some mixed-mode code to expose a .NET 1.1 managed API. Only the necessary files are compiled with /clr. We want to be able to load the application without .NET present, and then just disable the API. But we are not even able to give an error message when we start the application without mscoree.dll present. We have tried delay-loading mscoree.dll, but that did not help because the OS loader (at least on...
0
1297
by: AG | last post by:
Hi, I have implemented the ASP.Net Ihttphandler interface. Handler references the mixed dll (both managed/unmanaged code) that contains core C++ classes wrapped under managed c++ wrappers. ASP.NET worker process, sometimes while loading the handler and mixed dll associated with it, throws System::DLLNotFoundException. I have verified that all required Dlls are in the system path. I have the handler version up and running perfectly but...
0
1618
by: Oenone | last post by:
I have created a number of "plug-in" DLLs for my ASP.NET application which are dynamically loaded at run-time. This is done by locating the DLL file on disk and loading it using the Assembly.LoadFrom(Filename) function. It's important that the DLLs are shadowed by ASP.NET so that they can be easily updated. To get this to work I have placed the DLLs into the bin\ directory inside my web application. This seems to work fine. However, to...
5
1354
by: news.microsoft.com | last post by:
I'm strongly considering abandoning the one-physical-file-per-page model and going with an arcitecture that simply loads content from classes dynamically. There will be only one page that a user will go to, and all variation from navigation will come from AJAX calls to load and replace content in a main frame. .... so my concern with this is, perhaps the browsers will leak memory or do something obscurely wierd with enough loading and...
2
1713
by: =?Utf-8?B?SmF0aW5kZXI=?= | last post by:
Hi, I have written dlls in c# that are being used by other applications. My application works fine if I add these dlls to executable folder,but when I place these dlls in another folder my application crashes. Is there any way to load these dlls from folder other than executable folder. If yes, How will I do that.
8
3137
by: =?Utf-8?B?TWFyaw==?= | last post by:
We've got a wierd failure happening on just one machine. One part of our product uses a 3rd party search implementation (dtSearch). DtSearch has a native core (dten600.dll), late-bound, and a managed wrapper (dtSearchNetApi2.dll). For reasons unknown our build and msi packaging process includes dtSearchNetApi2.dll but not dten600.dll in all packages, as well as a couple of assemblies that reference it, even though they are not used by...
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.