473,606 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1932
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******@devel op.com> wrote in message
news:ei******** *****@TK2MSFTNG P09.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
5818
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. After some trial and error experiments, we've found out that a) the parameters must be ordered by type, i.e. we cannot mix double, integers and Strings (char-Arrays) - instead, we first need to put all the float-Arrays and Int32-Arrays, and...
13
7403
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 method to an IntPtr? / Christian
4
2058
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 multiple objects from said wrapper class? There's only one DLL, so is it creating multiple instances of its functions when each object is making calls to it? Does anyone know of any resources that explain this? Thanks, gilad
1
3602
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 only if I'm in the debugger. Here's a stack trace with non-user code shown -- the call to RegisterNotifySource, at the top of the stack, never returns -- I have to do a "break all" inside the debugger, then find this thread and examine its call...
0
908
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 fine. However I haven't yet found a really nice way to make sure that the DLL gets automatically copied to the same directory as the .EXE file so that it'll be available at runtime. Currently I'm using a Post-Build step in the DLL project to copy the...
0
2946
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 thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
7
5388
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 filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
5
11231
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 my project. When I run the solution, I get an error: Can't find PInvoke DLL 'winmm.dll'. I have my code below. Could someone please help? <code>
2
8398
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 Marshal.GetLastWin32Error immediately afterwards returns an errorcode of 0 indicating that the operation somehow executed successfully. This is a plain vanilla console app written in C#. It runs on vista and has a manifest embedded in it that...
1
1027
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. Can anybody tell me how to invoke the .net dll without giving the actual reference to the project? Regards
0
8036
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7978
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
8461
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...
1
8126
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8317
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5987
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
5470
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
3948
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...
1
2454
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.