writehtml方法中使用到的一个类
来源:互联网 发布:字符型数组java 编辑:程序博客网 时间:2024/05/29 18:46
/********************************
* 微软自身的接口声明
* 由于找不到可用的Interface声明
* 只好祭出Reflector,反编译Windows.Forms
* 需要的朋友可以不用辛苦的自己搞了
* ******************************/
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
namespace HtmlEditor {
[StructLayout(LayoutKind.Sequential)]
public class STATSTG {
[MarshalAs(UnmanagedType.LPWStr)]
public string pwcsName;
public int type;
[MarshalAs(UnmanagedType.I8)]
public long cbSize;
[MarshalAs(UnmanagedType.I8)]
public long mtime;
[MarshalAs(UnmanagedType.I8)]
public long ctime;
[MarshalAs(UnmanagedType.I8)]
public long atime;
[MarshalAs(UnmanagedType.I4)]
public int grfMode;
[MarshalAs(UnmanagedType.I4)]
public int grfLocksSupported;
public int clsid_data1;
[MarshalAs(UnmanagedType.I2)]
public short clsid_data2;
[MarshalAs(UnmanagedType.I2)]
public short clsid_data3;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b0;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b1;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b2;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b3;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b4;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b5;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b6;
[MarshalAs(UnmanagedType.U1)]
public byte clsid_b7;
[MarshalAs(UnmanagedType.I4)]
public int grfStateBits;
[MarshalAs(UnmanagedType.I4)]
public int reserved;
public STATSTG() {
}
}
[SuppressUnmanagedCodeSecurity]
internal class UnsafeNativeMethods {
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713")]
public interface IPersistStreamInit {
void GetClassID(out Guid pClassID);
[PreserveSig]
int IsDirty();
void Load([In, MarshalAs(UnmanagedType.Interface)] IStream pstm);
void Save([In, MarshalAs(UnmanagedType.Interface)] IStream pstm, [In, MarshalAs(UnmanagedType.Bool)] bool fClearDirty);
void GetSizeMax([Out, MarshalAs(UnmanagedType.LPArray)] long pcbSize);
void InitNew();
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0000000C-0000-0000-C000-000000000046")]
public interface IStream {
int Read(IntPtr buf, int len);
int Write(IntPtr buf, int len);
[return: MarshalAs(UnmanagedType.I8)]
long Seek([In, MarshalAs(UnmanagedType.I8)] long dlibMove, int dwOrigin);
void SetSize([In, MarshalAs(UnmanagedType.I8)] long libNewSize);
[return: MarshalAs(UnmanagedType.I8)]
long CopyTo([In, MarshalAs(UnmanagedType.Interface)] IStream pstm, [In, MarshalAs(UnmanagedType.I8)] long cb, [Out, MarshalAs(UnmanagedType.LPArray)] long[] pcbRead);
void Commit(int grfCommitFlags);
void Revert();
void LockRegion([In, MarshalAs(UnmanagedType.I8)] long libOffset, [In, MarshalAs(UnmanagedType.I8)] long cb, int dwLockType);
void UnlockRegion([In, MarshalAs(UnmanagedType.I8)] long libOffset, [In, MarshalAs(UnmanagedType.I8)] long cb, int dwLockType);
void Stat([Out] STATSTG pStatstg, int grfStatFlag);
[return: MarshalAs(UnmanagedType.Interface)]
IStream Clone();
}
// Methods
public UnsafeNativeMethods() {
}
public class ComStreamFromDataStream : IStream {
// Methods
protected ComStreamFromDataStream() {
this.virtualPosition = -1;
}
public ComStreamFromDataStream(Stream dataStream) {
this.virtualPosition = -1;
if (dataStream == null) {
throw new ArgumentNullException("dataStream");
}
this.dataStream = dataStream;
}
private void ActualizeVirtualPosition() {
if (this.virtualPosition != -1) {
if (this.virtualPosition > this.dataStream.Length) {
this.dataStream.SetLength(this.virtualPosition);
}
this.dataStream.Position = this.virtualPosition;
this.virtualPosition = -1;
}
}
public IStream Clone() {
ComStreamFromDataStream.NotImplemented();
return null;
}
public void Commit(int grfCommitFlags) {
this.dataStream.Flush();
this.ActualizeVirtualPosition();
}
public long CopyTo(IStream pstm, long cb, long[] pcbRead) {
int num1 = 0x1000;
IntPtr ptr1 = Marshal.AllocHGlobal(num1);
if (ptr1 == IntPtr.Zero) {
throw new OutOfMemoryException();
}
long num2 = 0;
try {
while (num2 < cb) {
int num3 = num1;
if ((num2 + num3) > cb) {
num3 = (int) (cb - num2);
}
int num4 = this.Read(ptr1, num3);
if (num4 == 0) {
goto Label_006C;
}
if (pstm.Write(ptr1, num4) != num4) {
throw ComStreamFromDataStream.EFail("Wrote an incorrect number of bytes");
}
num2 += num4;
}
}
finally {
Marshal.FreeHGlobal(ptr1);
}
Label_006C:
if ((pcbRead != null) && (pcbRead.Length > 0)) {
pcbRead[0] = num2;
}
return num2;
}
protected static ExternalException EFail(string msg) {
ExternalException exception1 = new ExternalException(msg, -2147467259);
throw exception1;
}
public Stream GetDataStream() {
return this.dataStream;
}
public void LockRegion(long libOffset, long cb, int dwLockType) {
}
protected static void NotImplemented() {
ExternalException exception1 = new ExternalException("Not implemented.", -2147467263);
throw exception1;
}
public int Read(IntPtr buf, int length) {
byte[] buffer1 = new byte[length];
int num1 = this.Read(buffer1, length);
Marshal.Copy(buffer1, 0, buf, length);
return num1;
}
public int Read(byte[] buffer, int length) {
this.ActualizeVirtualPosition();
return this.dataStream.Read(buffer, 0, length);
}
public void Revert() {
ComStreamFromDataStream.NotImplemented();
}
public long Seek(long offset, int origin) {
long num1 = this.virtualPosition;
if (this.virtualPosition == -1) {
num1 = this.dataStream.Position;
}
long num2 = this.dataStream.Length;
switch (origin) {
case 0: {
if (offset > num2) {
this.virtualPosition = offset;
break;
}
this.dataStream.Position = offset;
this.virtualPosition = -1;
break;
}
case 1: {
if ((offset + num1) > num2) {
this.virtualPosition = offset + num1;
break;
}
this.dataStream.Position = num1 + offset;
this.virtualPosition = -1;
break;
}
case 2: {
if (offset > 0) {
this.virtualPosition = num2 + offset;
break;
}
this.dataStream.Position = num2 + offset;
this.virtualPosition = -1;
break;
}
}
if (this.virtualPosition != -1) {
return this.virtualPosition;
}
return this.dataStream.Position;
}
public void SetSize(long value) {
this.dataStream.SetLength(value);
}
public void Stat(STATSTG pstatstg, int grfStatFlag) {
pstatstg.type = 2;
pstatstg.cbSize = this.dataStream.Length;
pstatstg.grfLocksSupported = 2;
}
public void UnlockRegion(long libOffset, long cb, int dwLockType) {
}
public int Write(IntPtr buf, int length) {
byte[] buffer1 = new byte[length];
Marshal.Copy(buf, buffer1, 0, length);
return this.Write(buffer1, length);
}
public int Write(byte[] buffer, int length) {
this.ActualizeVirtualPosition();
this.dataStream.Write(buffer, 0, length);
return length;
}
// Fields
protected Stream dataStream;
private long virtualPosition;
}
}
}
- writehtml方法中使用到的一个类
- “Caculate::writehtml”: 函数调用缺少参数列表;请使用“&Caculate::writehtml”创建指向成员的指针
- C# 委托:把方法组合到一个数组中使用
- 多线程中使用到的小方法
- 从SQL中导出到MYSQL的一个简单方法
- printStackTrace方法打出的详细信息存储到一个字符串中
- js中直接跳转到一个页面的方法
- 多个block合并到一个方法的使用
- 如何将自己的实体类封装到一个list中,定义自己一系列的方法
- 一个项目中使用到的通用函数库(1)
- 一个项目中使用到的通用函数库(1)
- [ASP.NET]工作中经常使用到的方法
- [ASP.NET]工作中经常使用到的方法
- [ASP.NET]工作中经常使用到的方法
- 方法中使用到的NSString是否需要dealloc?
- VS中使用“附加到进程”进行调试的方法
- WinHttp编程一般过程中会使用到的方法
- java 中String 经常会使用到的方法
- FreeBSD 单用户模式
- EasyJWeb-0.8.0版本发布
- js小技巧
- 一个表单数据检查思路....
- subversion启动脚本
- writehtml方法中使用到的一个类
- Google、迅雷与李开复、周鸿祎的那点破事
- 精解PCI Express
- 我的开发板的LED流水灯接口
- 是需要,還是想要?
- ButtonField 对象在 GridView 控件中如合使用
- 关于SAP的事务提交和回滚(LUW)
- 音频软件 Advanced WMA Workshop
- 什么是web标准