RE: Pointer of Struct
- From: dbgrick <dbgrick@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jul 2007 07:00:00 -0700
In your structure you need to specify the size of the string parameters. For
example:
public struct MyPerson
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr, SizeConst=50)]
public string first;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr, SizeConst=50)]
public string last;
}
Rick D.
Contractor
"Sasacha Jakob" wrote:
Hello,.
i have a problem while using
Marshal.SizeOf(...) on Windows CE 5.0
I get a NotSupportedException.
Here is my whole procedure:
public struct MyPerson {
public string first;
public string last;
}
private unsafe void Test() {
MyPerson myP = new MyPerson();
myP.first = "Tom";
myP.last = "Stevens";
// Get Pointer of myP
int size = Marshal.SizeOf(myP); // This Method throws the Exception
IntPtr buffer = Marshal.AllocCoTaskMem(size);
Marshal.StructureToPtr( myP, buffer, false );
}
When I try to run this Code as a Windows Desktop Application it runs great.
When I use the following struct (using char instead of string) it runs on
Windows CE 5.0 as well:
public struct MyPerson {
public char first;
public char last;
}
But I need string members of the sruct. What is my problem, and what can I
do.
Is this function of getting a pointer of struct actually not available on
Windows CE 5.0
Please Help me, thank you.
Best Regards
Sascha Jakob
- Follow-Ups:
- Re: Pointer of Struct
- From: Sasacha Jakob
- Re: Pointer of Struct
- From: Sasacha Jakob
- Re: Pointer of Struct
- References:
- Pointer of Struct
- From: Sasacha Jakob
- Pointer of Struct
- Prev by Date: Re: Send file and WLAN
- Next by Date: Re: Pointer of Struct
- Previous by thread: Pointer of Struct
- Next by thread: Re: Pointer of Struct
- Index(es):
Relevant Pages
|