473,402 Members | 2,055 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,402 software developers and data experts.

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

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).
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 2400
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.NullReferenceException : 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*****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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
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...
4
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...
1
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...
1
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++...
10
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...
1
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,...
3
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...
7
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...
7
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...

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.