PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework PtrToStructure killing pointers

Reply

PtrToStructure killing pointers

 
Thread Tools Rate Thread
Old 15-01-2006, 10:04 PM   #1
=?Utf-8?B?dGIyMDAw?=
Guest
 
Posts: n/a
Default PtrToStructure killing pointers


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
}


  Reply With Quote
Old 15-01-2006, 10:23 PM   #2
=?Utf-8?B?dGIyMDAw?=
Guest
 
Posts: n/a
Default RE: PtrToStructure killing pointers

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
> }
>
>

  Reply With Quote
Old 15-01-2006, 10:52 PM   #3
Gilles Kohl [MVP]
Guest
 
Posts: n/a
Default Re: PtrToStructure killing pointers

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)

  Reply With Quote
Old 16-01-2006, 06:23 AM   #4
=?Utf-8?B?dGIyMDAw?=
Guest
 
Posts: n/a
Default Re: PtrToStructure killing pointers

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)
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off