PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
PtrToStructure killing pointers
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
PtrToStructure killing pointers
![]() |
PtrToStructure killing pointers |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 } |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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..... "tb2000" wrote: > 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 > } > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
On Sun, 15 Jan 2006 14:04:01 -0800, tb2000
<tb2000@discussions.microsoft.com> wrote: >I am using .NETCF 2.0.5238.0 and presently (as VS2005 is unavailable in >Germany) still VS .NET 2003 You can order Visual Studio in Germany e.g. here: http://www.zoschke.com/default.asp Regards, Gilles [MVP]. (Please reply to the group, not via email) |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. "Gilles Kohl [MVP]" wrote: > On Sun, 15 Jan 2006 14:04:01 -0800, tb2000 > <tb2000@discussions.microsoft.com> wrote: > > >I am using .NETCF 2.0.5238.0 and presently (as VS2005 is unavailable in > >Germany) still VS .NET 2003 > > You can order Visual Studio in Germany e.g. here: > > http://www.zoschke.com/default.asp > > Regards, > Gilles [MVP]. > > (Please reply to the group, not via email) > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

