473,409 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

P/Invoke DLL-memory managment

Hello,

I'm looking for information about the loading/unloading of unmanaged dlls.

Using the debugger I think it works as follows : the unmanaged DLL is
loaded as soon as a call to one of it's functions is made. After that,
it's kept in memory till the last call to it (by the managed program) is
done. After that it's unloaded.

Is this behaviour correct? Or is it possible that the DLL is unloaded
somewhere halfway my program? If I make a call to it than do
calculations for 4 days and then call it again would it stay loaded in
memory?

I was thinking about calling an initializing function which allocates
memory and use it later but i can't find any articles stating if that
would work or not (especially when the dll doesn't contain a
DllMain-function which is used to keep reference if i understand it well)

TIA

Yves
Jul 21 '05 #1
3 1908
AFAIK once a DLL is loaded via P/Invoke it us nt unloaded until the process exits. Are you seeing smething different?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hello,

I'm looking for information about the loading/unloading of unmanaged dlls.

Using the debugger I think it works as follows : the unmanaged DLL is
loaded as soon as a call to one of it's functions is made. After that,
it's kept in memory till the last call to it (by the managed program) is
done. After that it's unloaded.

Is this behaviour correct? Or is it possible that the DLL is unloaded
somewhere halfway my program? If I make a call to it than do
calculations for 4 days and then call it again would it stay loaded in
memory?

I was thinking about calling an initializing function which allocates
memory and use it later but i can't find any articles stating if that
would work or not (especially when the dll doesn't contain a
DllMain-function which is used to keep reference if i understand it well)

TIA

Yves

Jul 21 '05 #2
Unless you are explicitely unloading/unmapping the dll (by calling
FreeLibrary), it stays mapped into the process space until process shutdown.

Willy.

"Yves Dhondt" <no@privacy.net> wrote in message
news:41***********************@news.skynet.be...
Hello,

I'm looking for information about the loading/unloading of unmanaged dlls.

Using the debugger I think it works as follows : the unmanaged DLL is
loaded as soon as a call to one of it's functions is made. After that,
it's kept in memory till the last call to it (by the managed program) is
done. After that it's unloaded.

Is this behaviour correct? Or is it possible that the DLL is unloaded
somewhere halfway my program? If I make a call to it than do calculations
for 4 days and then call it again would it stay loaded in memory?

I was thinking about calling an initializing function which allocates
memory and use it later but i can't find any articles stating if that
would work or not (especially when the dll doesn't contain a
DllMain-function which is used to keep reference if i understand it well)

TIA

Yves

Jul 21 '05 #3
Not at all, just wanted to be sure about it, I couldn't find it back in the
docs.

Thanks

Yves

"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:ei*************@TK2MSFTNGP09.phx.gbl...
AFAIK once a DLL is loaded via P/Invoke it us nt unloaded until the
process exits. Are you seeing smething different?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hello,

I'm looking for information about the loading/unloading of unmanaged dlls.

Using the debugger I think it works as follows : the unmanaged DLL is
loaded as soon as a call to one of it's functions is made. After that,
it's kept in memory till the last call to it (by the managed program) is
done. After that it's unloaded.

Is this behaviour correct? Or is it possible that the DLL is unloaded
somewhere halfway my program? If I make a call to it than do
calculations for 4 days and then call it again would it stay loaded in
memory?

I was thinking about calling an initializing function which allocates
memory and use it later but i can't find any articles stating if that
would work or not (especially when the dll doesn't contain a
DllMain-function which is used to keep reference if i understand it well)

TIA

Yves

Jul 21 '05 #4

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

Similar topics

3
by: Holger (David) Wagner | last post by:
Hi all, we're currently developing an application in the .NET environment that needs to access a DLL implemented in Fortran. There is one procedure with about 17 parameters, most of them arrays....
13
by: Christian Westerlund | last post by:
Hi! I'm trying to use P/Invoke and a Method which takes an IntPtr where I am supposed to put an address to a method which the native method will use to communicate back to me. How do I convert a...
4
by: gilad | last post by:
If a DLL has been created to be thread-safe, and you create a wrapper class around it in C# that is non-static (i.e. you must instantiate objects from it), what are the implications of creating...
1
by: Gregory Hassett | last post by:
Hi, I have a web service called GetComputerNameAndDescription which I can call from the main thread of my app. If I call it from a separate thread, however, it hangs on the call to Invoke() -- but...
0
by: Steve Terepin | last post by:
I have a Solution that consists of two projects, one written in C/C++ that builds a DLL, and another written in C# that builds an EXE. I'm using P/Invoke to call the DLL, and it all works just...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the...
5
by: krupa.p | last post by:
Hi All, I am trying to call the waveOutGetVolume() function in winmm.dll from my VS 2005 C# project using P/Invoke. I copied winmm.dll from Windows\system32 directory into the root directory of...
2
by: rdilipk | last post by:
I am posting at the end of this post some code that P/Invoke's SetSystemTime to set the local system time. This call fails -- i.e the time is not set and the API returns false. However calling...
1
by: amollokhande1 | last post by:
Hi All, I am inprocess of writting the procedure, that will invoke any method from any .net dll. Requirement for this procedure is that dll will not be avaiable as a reference to the project. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.