RE: Pointer of Struct

Tech-Archive recommends: Speed Up your PC by fixing your registry



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



.



Relevant Pages

  • Pointer of Struct
    ... public struct MyPerson { ... public string first; ... When I try to run this Code as a Windows Desktop Application it runs great. ...
    (microsoft.public.pocketpc.developer)
  • Re: Pointer of Struct
    ... public string first; ... public struct MyPerson { ... When I try to run this Code as a Windows Desktop Application it runs ...
    (microsoft.public.pocketpc.developer)
  • Re: Pointer of Struct
    ... I use the following struct: ... public string pcCountry; ... public struct MyPerson { ... When I try to run this Code as a Windows Desktop Application it runs ...
    (microsoft.public.pocketpc.developer)
  • Creating Local User with Web Service
    ... Hi I am very new to .NET and I am programmatically trying to create a windows ... users and am having a little trouble. ... argument does not seem to take, here is the code (this is my first crack at ... public string CreateLocalUser ...
    (microsoft.public.dotnet.framework.webservices)