您可以在这里快速查找:


 
您的位置: 编程学习 > asp.net教程 > 200509
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

使用C#拷贝String到struct

wwfttelne

使用C#拷贝String到struct

By dgiljr

介绍

本文介绍使用C#拷贝String到struct 

代码

using System;using System.Runtime.InteropServices;using System.Text; class Class1{     [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]    public struct MyStruct    {        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=4)] public string fname;        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=4)] public string lname;        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=7)] public string phone;    }        public static void Main()    {        string buffer = "abcdefgh2223333";        IntPtr pBuf = Marshal.StringToBSTR(buffer);        MyStruct ms = (MyStruct)Marshal.PtrToStructure(pBuf,typeof(MyStruct));        Console.WriteLine("fname is: {0}",ms.fname);        Console.WriteLine("lname is: {0}",ms.lname);        Console.WriteLine("phone is: {0}",ms.phone);    }}

 

From :

http://www.codeproject.com/csharp/gil_structs.asp

 

 

                                                                                          biqiong2004@hotmail.com

                          http://home.ripway.com/2004-6/124912/