Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="MainHandleType"></typeparam>
 /// <typeparam name="SecondHandleType"></typeparam>
 /// <typeparam name="InfoType"></typeparam>
 /// <param name="mainHandle"></param>
 /// <param name="secondHandle"></param>
 /// <param name="paramName"></param>
 /// <param name="getInfoDelegate"></param>
 /// <returns></returns>
 protected string GetStringInfo <MainHandleType, SecondHandleType, InfoType>
     (MainHandleType mainHandle, SecondHandleType secondHandle, InfoType paramName, GetInfoDelegateEx <MainHandleType, SecondHandleType, InfoType> getInfoDelegate)
 {
     byte[] buffer = GetArrayInfo <MainHandleType, SecondHandleType, InfoType, byte>(mainHandle, secondHandle, paramName, getInfoDelegate);
     char[] chars  = Encoding.UTF8.GetChars(buffer, 0, buffer.Length);
     return((new string(chars)).TrimEnd(new char[] { '\0' }));
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="MainHandleType"></typeparam>
        /// <typeparam name="SecondHandleType"></typeparam>
        /// <typeparam name="InfoType"></typeparam>
        /// <typeparam name="QueriedType"></typeparam>
        /// <param name="mainHandle"></param>
        /// <param name="secondHandle"></param>
        /// <param name="paramName"></param>
        /// <param name="getInfoDelegate"></param>
        /// <returns></returns>
        protected QueriedType GetInfo <MainHandleType, SecondHandleType, InfoType, QueriedType>
            (MainHandleType mainHandle, SecondHandleType secondHandle, InfoType paramName, GetInfoDelegateEx <MainHandleType, SecondHandleType, InfoType> getInfoDelegate)
            where QueriedType : struct
        {
            QueriedType result   = new QueriedType();
            GCHandle    gcHandle = GCHandle.Alloc(result, GCHandleType.Pinned);

            try
            {
                IntPtr           sizeRet;
                ComputeErrorCode error = getInfoDelegate(mainHandle, secondHandle, paramName, new IntPtr(Marshal.SizeOf(result)), gcHandle.AddrOfPinnedObject(), out sizeRet);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                result = (QueriedType)gcHandle.Target;
                gcHandle.Free();
            }

            return(result);
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TMainHandleType"></typeparam>
 /// <typeparam name="TSecondHandleType"></typeparam>
 /// <typeparam name="TInfoType"></typeparam>
 /// <param name="mainHandle"></param>
 /// <param name="secondHandle"></param>
 /// <param name="paramName"></param>
 /// <param name="getInfoDelegate"></param>
 /// <returns></returns>
 protected static string GetStringInfo <TMainHandleType, TSecondHandleType, TInfoType>
     (TMainHandleType mainHandle, TSecondHandleType secondHandle, TInfoType paramName, GetInfoDelegateEx <TMainHandleType, TSecondHandleType, TInfoType> getInfoDelegate)
 {
     byte[] buffer = GetArrayInfo <TMainHandleType, TSecondHandleType, TInfoType, byte>(mainHandle, secondHandle, paramName, getInfoDelegate);
     char[] chars  = Encoding.ASCII.GetChars(buffer, 0, buffer.Length);
     return(new string(chars).TrimEnd('\0'));
 }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="MainHandleType"></typeparam>
        /// <typeparam name="SecondHandleType"></typeparam>
        /// <typeparam name="InfoType"></typeparam>
        /// <typeparam name="QueriedType"></typeparam>
        /// <param name="mainHandle"></param>
        /// <param name="secondHandle"></param>
        /// <param name="paramName"></param>
        /// <param name="getInfoDelegate"></param>
        /// <returns></returns>
        protected QueriedType[] GetArrayInfo <MainHandleType, SecondHandleType, InfoType, QueriedType>
            (MainHandleType mainHandle, SecondHandleType secondHandle, InfoType paramName, GetInfoDelegateEx <MainHandleType, SecondHandleType, InfoType> getInfoDelegate)
        {
            ComputeErrorCode error;

            QueriedType[] buffer;
            IntPtr        bufferSizeRet;

            error = getInfoDelegate(mainHandle, secondHandle, paramName, IntPtr.Zero, IntPtr.Zero, out bufferSizeRet);
            ComputeException.ThrowOnError(error);
            buffer = new QueriedType[bufferSizeRet.ToInt64() / Marshal.SizeOf(typeof(QueriedType))];
            GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            try
            {
                error = getInfoDelegate(mainHandle, secondHandle, paramName, bufferSizeRet, gcHandle.AddrOfPinnedObject(), out bufferSizeRet);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                gcHandle.Free();
            }
            return(buffer);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TMainHandleType"></typeparam>
        /// <typeparam name="TSecondHandleType"></typeparam>
        /// <typeparam name="TInfoType"></typeparam>
        /// <typeparam name="TQueriedType"></typeparam>
        /// <param name="mainHandle"></param>
        /// <param name="secondHandle"></param>
        /// <param name="paramName"></param>
        /// <param name="getInfoDelegate"></param>
        /// <returns></returns>
        protected static TQueriedType[] GetArrayInfo <TMainHandleType, TSecondHandleType, TInfoType, TQueriedType>
            (TMainHandleType mainHandle, TSecondHandleType secondHandle, TInfoType paramName, GetInfoDelegateEx <TMainHandleType, TSecondHandleType, TInfoType> getInfoDelegate)
        {
            var error = getInfoDelegate(mainHandle, secondHandle, paramName, IntPtr.Zero, IntPtr.Zero, out var bufferSizeRet);

            ComputeException.ThrowOnError(error);
            var      buffer   = new TQueriedType[bufferSizeRet.ToInt64() / Marshal.SizeOf(typeof(TQueriedType))];
            GCHandle gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            try
            {
                error = getInfoDelegate(mainHandle, secondHandle, paramName, bufferSizeRet, gcHandle.AddrOfPinnedObject(), out bufferSizeRet);
                ComputeException.ThrowOnError(error);
            }
            finally
            {
                gcHandle.Free();
            }
            return(buffer);
        }