473,396 Members | 2,021 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,396 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 1907
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
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...

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.