473,326 Members | 2,147 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,326 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 !
Nov 17 '05 #1
4 1393
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 ?

Nov 17 '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.
Nov 17 '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.

Nov 17 '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.

Nov 17 '05 #5

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

Similar topics

0
by: Denis | last post by:
Hello, I am working on a large business application written mostly with VC++ and MFC. What I'm trying to do is accessing my database with the existing functions in my c++ application using XML...
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...
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...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.