zoukankan      html  css  js  c++  java
  • 好类 笔记 武胜

    View Code
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace CalmBeltFund.Trading.CTPStock
    {
      internal class PInvokeUtility
      {
        static Encoding encodingGB2312 = Encoding.GetEncoding(936);
    
        public static string GetUnicodeString(byte[] str)
        {
    
          if (str == null)
          {
            return "";
          }
    
          byte[] unicodeStr = Encoding.Convert(encodingGB2312, Encoding.Unicode, str);
    
          return Encoding.Unicode.GetString(unicodeStr).TrimEnd('\0');
        }
    
        public static T GetObjectFromIntPtr<T>(IntPtr handler)
        {
          try
          {
            if (handler == IntPtr.Zero)
            {
              return default(T);
            }
            else
            {
              return (T)Marshal.PtrToStructure(handler, typeof(T));
            }
          }
          catch (Exception ex)
          {
            throw ex;
          }
        }
    
        public static object GetObjectFromIntPtr(Type t,IntPtr handler)
        {
          try
          {
            if (handler == IntPtr.Zero)
            {
              return null;
            }
            else
            {
              return Marshal.PtrToStructure(handler, t);
            }
          }
          catch (Exception ex)
          {
            throw ex;
          }
        }
      }
    }
  • 相关阅读:
    属性选择器
    Map
    tomcat 启动失败
    find for /f 分割字符串 bat
    oracle 1day
    scott lock
    oracle oracle sqldeveloper 12505 创建连接失败
    oracle sql developer 启动java.exe设置错误
    servlet post response.sendRedirect 乱码

  • 原文地址:https://www.cnblogs.com/zeroone/p/3036968.html
Copyright © 2011-2022 走看看