PtrToStructure killing pointers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using .NETCF 2.0.5238.0 and presently (as VS2005 is unavailable in
Germany) still VS .NET 2003

I am working on interop between an unsave C-written DLL and C#.

Now, in a constructor of a class I am trying to get a structure copied from
unsafe to a safe structure (class actually) using Marshal.PtrToStructure
(IntPtr, Object). Returning from here my pointer goes to 0. What am I missing?
I tried the same with Marshal.PtrToStructure (IntPtr, Type) and IntPtr is
not null thereafter (but as I am using it in the constructor I guess I need
to use the first one). Regardless which version is used, the managed
structure/class properly receives the values from the unmanaged side
Thanks ahead for any help!!
tb

PS: here's the code:
..
..
public IntPtr cp;
//constructor
public WrapCP()
{
cp = myUnsafeDll_new();
log.Debug("cp initialized " + (int)cp); // this confirms a non zero return
value
Marshal.PtrToStructure(cp,this); //this properly fills the struct/class
log.Debug("cp now " + (int)cp); // cp now points to 0
}
 
One addition:
saving the Pointer to an int and restoring it resolved the problem
int cp1=cp.ToInt32;
Marshal.....
cp = (IntPtr)cp1;
however I still think I am misisng something I don't understand yet,
so any feedback is truly welcome.....
 
Thanks for the lead. but will this solve my problem?

Btw: the VS Edition I need is shipping Feb06 according to that website. I
will probably go and get a US version.
 
Back
Top