使用C#拷贝String到struct
来源:互联网 发布:shadow defender 知乎 编辑:程序博客网 时间:2024/05/16 10:38
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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/12
拷贝String到struct';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
使用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/12
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 使用C#拷贝String到struct
- 使用C#拷贝String到struct
- multimap <string, struct>使用范例
- vs2013 使用string,struct,指针
- c# 拷贝文件到"启动"文件夹中
- 拷贝文件到指定路径 wince C#
- 拷贝文件到指定路径 wince C#
- C# 拷贝文件到另一个目录
- C# 拷贝文件夹到指定目录
- C# API复制/拷贝到剪辑板
- c#中从string到string[]
- 关于C#中 struct使用new 初始化
- C#中使用List<struct>的问题
- c# struct
- c# struct 变量 到 byte[] 变量的转换操作
- c# struct 变量 到 byte[] 变量的转换操作
- c# struct 变量 到 byte[] 变量的转换操作
- 《C#入门到精通》学习笔记 -- enum 和 struct
- 手工转移数据库Step By Step
- 一段log execption 的代码
- 伟大的解决方案—DataWindow.Net(一)
- 大数据量下的分页
- 如何在Windows 2000环境中Kill掉单个Oracle线程
- 使用C#拷贝String到struct
- SQL SERVER 2000系统提供的跟踪函数(一)
- Visual Basic .NET中的异常处理简介(上)
- SQL SERVER 2000系统提供的跟踪函数(二)
- beta2中的SqlConnection和SqlCommand
- Mysql的常用命令
- 一番话:抽象工厂
- ORACLE性能诊断―学习statspack笔记(三)[表的分类]
- EPower2002示例:运用"工厂方法"设计类