Strange Problem With Interop

  • Thread starter Thread starter batista
  • Start date Start date
B

batista

Hi there,

i have a web service which is using a dll written in vc7.This dll in
turn is accessing a vc6 com dll through interop.

Now the problem is that i have a function in vc6 that takes as param
zipped data and returns me unzip data.The params it takes r
1)the starting memory address of the zipped data
2)the length of the zipped data
3)an empty string in which the unzip data is returned(out param)
4)length of unzipped data

Now when i call this method from my web service through the vc7 dll,
sometimes it returns me the correct unzipped data and sometimes it does
not.

My question is why is the same code giving me different results?

BTW, the unzipping of the data is done using a very well tested API so
there shud be no problem with the unzipping of data.

I think it has something to do with managed/unmanaged memory,not really
sure...
So, plz help me out on this...

Bye.
 
One possible reason might be is that the GC does memory optimization
when running, so it moves memory locations around for a more compact
heap. If you are passing in some pointer/ref variables to the VC lib,
which then passes those to the vb6 program, it might happen that the GC
at times might move memory around while the vb6 program is running,
thus the garbled message...

One possible solution could be to use the fixed statement to pin the
memory location of your managed variables and then call the VC lib to
do the unzipping...

unsafe void UnzipSomething (string something)
{
string unzipped = string.Empty;
char[] values = something.ToCharArray ();
int length = values.Length;
fixed (char* test = &values[0])
{
//
}
}
 
Back
Top