예제 #1
0
 public unsafe StrRet(StrRetNative value)
 {
     IntPtr dataStart = (IntPtr)(&value.cStr[0]);
     switch (value.uType)
     {
         case StrRetNative.StrRetType.CStr:
             this.value = Marshal.PtrToStringAnsi(dataStart, 260); //MAX_PATH
             return;
         case StrRetNative.StrRetType.WStr:
             IntPtr strAddr = *(IntPtr*)(dataStart + sizeof(IntPtr) - sizeof(int));
             try
             {
                 this.value = Marshal.PtrToStringUni(strAddr);
                 return;
             }
             finally
             {
                 Marshal.FreeCoTaskMem(strAddr);
             }
         case StrRetNative.StrRetType.Offset:
             offset = *(int*)dataStart;
             return;
         default:
             throw new ArgumentException(String.Format("Invalid type of StrRet: {0}", (int)value.uType), "pNativeData");
     }
 }
예제 #2
0
        public unsafe StrRet(StrRetNative value)
        {
            IntPtr dataStart = (IntPtr)(&value.cStr[0]);

            switch (value.uType)
            {
            case StrRetNative.StrRetType.CStr:
                this.value = Marshal.PtrToStringAnsi(dataStart, 260);     //MAX_PATH
                return;

            case StrRetNative.StrRetType.WStr:
                IntPtr strAddr = *(IntPtr *)(dataStart + sizeof(IntPtr) - sizeof(int));
                try
                {
                    this.value = Marshal.PtrToStringUni(strAddr);
                    return;
                }
                finally
                {
                    Marshal.FreeCoTaskMem(strAddr);
                }

            case StrRetNative.StrRetType.Offset:
                offset = *(int *)dataStart;
                return;

            default:
                throw new ArgumentException(String.Format("Invalid type of StrRet: {0}", (int)value.uType), "pNativeData");
            }
        }