473,725 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling unmanaged dll from .NET C# service causes pointer corruption eve if used InitializeLifet imeService

Hi,

I have made a service with C# and calling that service class from another C#
program with remoting.
(Referendes from the calling program)
That service class is configured so that garpage collection is not used in
this class.
(singleton class + override InitializeLifet imeService )

The service class uses C++ unmanaged function from dll (using DLLimport).
The C++ function uses void pointer which is corrupted after the solution is
called some times.
The void pointer is allocated in the C++ code (dll) when one class is
allocated dynamically (with new).
The pointer is not marshaled to the service class.

I think that the problem is maybe .NET garpage collection in this case,
because same solution is working when calling from an ordinary C++ code
(unmanaged).

How is the memory handling going in this case ?
Is it possible that the .NET service code still frees the memory even if it
is in unmanaged dll ?
Should it help if the pointer is marshaled to the service singleton class or
would the situation be the same ?
(This is the next Iam going to try)
Thanks !
Jul 21 '05 #1
4 2430
Hi,
yes it seems that when this is not called say about 2 minutes, it is not
working any more.

It gives error message:
System.NullRefe renceException : Object reference not set to an instance of
an object.

Has anybody idea why this happens ?

Jul 21 '05 #2
Hi again,

found the reason.

When the C++ unmanaged function from dll is called, the caller is from
another thread that is whu the original void pointer is not valid any more.
I do not know why the new thread is born, but that was the original reason
for this behaviour.
Jul 21 '05 #3

"jarmopy" <ja*****@discus sions.microsoft .com> wrote in message
news:9C******** *************** ***********@mic rosoft.com...
Hi again,

found the reason.

When the C++ unmanaged function from dll is called, the caller is from
another thread that is whu the original void pointer is not valid any
more.
I do not know why the new thread is born, but that was the original reason
for this behaviour.

I don't believe this is the reason, the function you called returns a
(valid?) pointer to unmanaged memory to the caller, the fact that you use
this same pointer on another thread (which you don't know where he comes
from!) doesn't make it an invalid pointer. Supposed this was the reason,
how did you solve the issue?

Willy.

Jul 21 '05 #4
Hi Willy,

the correction was done in the C++ code (that what I was calling).
The guy who corrected it said that this happens if the function is called
from an another thread than the previous call. I do not know the exact
correction method but now is is working OK.

Jul 21 '05 #5

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

Similar topics

15
11788
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
4
1413
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage collection is not used in this class. (singleton class + override InitializeLifetimeService ) The service class uses C++ unmanaged function from dll (using DLLimport).
1
1917
by: Nick Bishop | last post by:
I have a problem where I call a method in a C++ class with a pointer which is a static member in that class. When I use a debugger, I see the pointer having a certain value, but when I step into the method (F11), the pointer has a different value and is not pointing at anything valid. The small program (complete source below) demonstrates what I am trying to achieve. The small program works perfectly, but when I incorporate this logic...
1
1278
by: Hamad Deshmukh | last post by:
Hey everyone, I have an issue that requires an urgent solution. I had a look at the Technote above, and it states that the AppDomainUnloaded Exception occurs with ASP.NET when using Managed C++ extensions as a wrapper to Unmanaged C++ calls. I am, however, seeing a similar problem with ASP.NET and my remoting Managed VC++ .NET components. However, my remoted VC++ .NET components do not call any Unmanaged code whatsoever.
10
2082
by: Gustavo L. Fabro | last post by:
Greetings! I've been porting an application for Builder to VS .NET 2003 and searching for possible bottlenecks (the application is currently running slow). I found out one scenario that takes a test function 125x more time to execute when the DLL is compiled with the /CLR parameter then when compiled without it. Average timings: -----------------------------
1
2603
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender, System::EventArgs * e) { MyDLLInit(MyAppDisplayFunction); }
3
4710
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC application. Furthermore, I use a pointer to an unmanaged function to jump back into the managed dll. The managed part is basically a remoting enhancement which asynchronly
7
2686
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
7
1524
by: mariescottandeva | last post by:
Hi, I need to call an old C DLL from my Web Service. This in itself is fine and I am able to do this no problem. My issue is that I need to call the DLL thousands of times, and it has memory leak and memory corruption problems, so after a while it dies with a memory corruption error. I donot have the option of fixing the memory leak, so I need to come up with a solution. my understanding is is the once an external dll is imported...
0
8752
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
9257
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...
1
9176
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
9113
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...
0
8097
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
6702
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
6011
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();...
1
3221
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
2
2635
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.