using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) {
{
*buf++ =(char) qty;
*buf++ = (char)(qty >> 8);
*buf++ = (char)(qty >> 16);
*buf++ = (char)(qty >> 24);
return (buf);
}
要打开不安全代码开关。
菜单“项目”--“属性”--“生成”--“允许不安全代码”前面打勾
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
float ft = 999999.999f; byte[] bytes = BitConverter.GetBytes(ft); unsafe
{ IntPtr i2= Marshal.AllocHGlobal(bytes.Length);
Marshal.Copy(bytes, 0, i2, bytes.Length);
byte *buf1 = (byte*)QtyToBuf((byte *)i2, 8); }
} unsafe void* QtyToBuf(byte* buf, UInt32 qty)
{
*buf++ = (byte)qty;
*buf++ = (byte)(qty >> 8);
*buf++ = (byte)(qty >> 16);
*buf++ = (byte)(qty >> 24);
return (buf);
}
}
}不确定qty的值,随便写的一个值。
有没有C的DEMO,好确定结果。