none
BaseClassesの一部をC#でテストしてもうまくいきません。どなたか教えてください。 RRS feed

  • 質問

  • using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using REFERENCE_TIME = System.Int64;
    namespace Test1
    {
      [StructLayout( LayoutKind.Sequential,Pack=4)]
      public struct RGBQUAD
      {
        public byte rgbBlue;
        public byte rgbGreen;
        public byte rgbRed;
        public byte rgbReserved;
      };
      [StructLayout( LayoutKind.Sequential,Pack=4)]
      public struct RECT
      {
        public int left;
        public int top;
        public int right;
        public int bottom;
      }
      [StructLayout(LayoutKind.Sequential,Pack=4)]
      public struct VIDEOINFOHEADER
      {
        public RECT rcSource;     // The bit we really want to use
        public RECT rcTarget;     // Where the video should go
        public uint dwBitRate;     // Approximate bit data rate
        public uint dwBitErrorRate;  // Bit error rate for this stream
        public REFERENCE_TIME AvgTimePerFrame;  // Average time per frame (100ns units)
    
        public BITMAPINFOHEADER bmiHeader;
    
      }
      public enum BI : uint
      {
        /// <summary>
        /// 無圧縮通常形式
        /// </summary>
        BI_RGB = 0,
        /// <summary>
        /// 8bit 連長圧縮形式
        /// </summary>
        BI_RLE8 = 1,
        /// <summary>
        /// 4bit 連長圧縮形式
        /// </summary>
        BI_RLE4 = 2,
        /// <summary>
        /// 無圧縮拡張形式
        /// </summary>
        BI_BITFIELDS = 3,
        /// <summary>
        /// JPEG圧縮方式
        /// </summary>
        BI_JPEG = 4,
        /// <summary>
        /// PING圧縮方式
        /// </summary>
        BI_PNG = 5,
      };
      [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)]
      public struct BITMAPINFOHEADER
      {
    
        public int biSize;
        public int biWidth;
        public int biHeight;
        public ushort biPlanes;
        public ushort biBitCount;
        public uint biCompression;
        public uint biSizeImage;
        public int biXPelsPerMeter;
        public int biYPelsPerMeter;
        public uint biClrUsed;
        public uint biClrImportant;
        
      }
      
      [StructLayout(LayoutKind.Sequential)]
      public struct TRUECOLORINFO
      {
        [MarshalAs(UnmanagedType.ByValArray,/*UnmanagedType.SafeArray= UnmanagedType.U8,*/  SizeConst = 3)]
        public uint[] dwBitMasks;
        [MarshalAs(UnmanagedType.ByValArray,/*UnmanagedType.SafeArray= UnmanagedType.Struct,*/ SizeConst = 256)]
        public RGBQUAD[] bmiColors;
      };
      public static unsafe class Win32Api
      {
        [DllImport("msvcrt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern int printf(string format, byte b1, byte b2, byte* b3);
        [DllImport("msvcrt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern int printf(string format, byte b1, byte b2, byte* b3, byte b4);
        [DllImport("kernel32.dll")]
        static extern unsafe void CopyMemory(void* dst, void* src, int size);
        [DllImport("msvcrt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern int printf(string format, int b1, int b2, void* b3);
      }
      public unsafe class Program
      {
        public static unsafe void TRUECOLORTEST(VIDEOINFOHEADER pbmi)
        {
          IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BITMAPINFOHEADER)) + Marshal.SizeOf(typeof(VIDEOINFOHEADER)) + pbmi.bmiHeader.biSize);
    
          Console.WriteLine("Marshal.SizeOf(typeof(BITMAPINFOHEADER)) = {0}", Marshal.SizeOf(typeof(BITMAPINFOHEADER)));
          Console.WriteLine("Marshal.SizeOf(typeof(BITMAPINFOHEADER)) = {0}", Marshal.SizeOf(typeof(VIDEOINFOHEADER)));
    
          Marshal.StructureToPtr(pbmi.bmiHeader, p, false);
          byte* PBYTE = (byte*)(void*)p;
          PBYTE += pbmi.bmiHeader.biSize;
          Win32Api.printf("data = %d, 16進数 = %x, アドレス = %p \n", *PBYTE, *PBYTE, PBYTE);
         }
    
        static void Main(string[] args)
        {
          /*
           * 設定した値は適当です
           */
          BITMAPINFOHEADER binfoh = new BITMAPINFOHEADER();
          binfoh.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
          binfoh.biWidth = 500;
          binfoh.biHeight = 500;
          binfoh.biPlanes = 1;
          binfoh.biCompression = (uint)BI.BI_BITFIELDS;
          binfoh.biSizeImage = 0;
          binfoh.biXPelsPerMeter = 0;
          binfoh.biYPelsPerMeter = 0;
          binfoh.biClrUsed = 256;
          binfoh.biClrImportant = 0;
          VIDEOINFOHEADER v = new VIDEOINFOHEADER();
          RECT rs = new RECT(), rt = new RECT();
          rs.top = 0;
          rs.left = 0;
          rs.right = 100;
          rs.bottom = 100;
          rt.top = 0;
          rt.left = 0;
          rt.right = 200;
          rt.bottom = 200;
          v.rcSource = rs;
          v.rcTarget = rt;
          v.dwBitRate = 10;
          v.dwBitErrorRate = 100;
          v.bmiHeader = binfoh;
          
          TRUECOLORTEST(v);
          
          Console.WriteLine("RECT = {0},BITMAPINFOHEADER = {1} ,VIDEOINFOHEADER = {2},TRUECOLORINFO = {3} \n", Marshal.SizeOf(typeof(RECT)), Marshal.SizeOf(typeof(BITMAPINFOHEADER)), Marshal.SizeOf(typeof(VIDEOINFOHEADER)), Marshal.SizeOf(typeof(TRUECOLORINFO)));
    
        }
      }
    }
    
    
    DirectShowのBaseClassesの一部を再現しようと思って以上のようなコードを書いたんですが
     Marshal.StructureToPtr(pbmi.bmiHeader, p, false);
     byte* PBYTE = (byte*)(void*)p;
     PBYTE += pbmi.bmiHeader.biSize;
     Win32Api.printf("data = %d, 16進数 = %x, アドレス = %p \n", *PBYTE, *PBYTE, PBYTE);
    


    の部分で値を見ると118になるんですが、BaseClassesのほうでは204になっています。

    どのようにしたら、204となるんでしょうか。すいませんが、どなたかご教示ください。

    2011年8月11日 0:22

回答

  • > Marshal.StructureToPtr(pbmi.bmiHeader, p, false);
    > byte* PBYTE = (byte*)(void*)p;
    > PBYTE += pbmi.bmiHeader.biSize;

    BITMAPINFOHEADER の先頭から、SizeOf(BITMAPINFOHEADER) 進めた場所…つまり、BITMAPINFOHEADER の終端の外側=コピーされたメモリ領域の後ろにあるゴミを表示されているのですよね?

    > 値を見ると118になるんですが、BaseClassesのほうでは204になっています。

    「BaseClasses のほう」がどこにもないのでわかりませんが、Microsoft C++ ではデバッグビルド時には確保されたメモリ領域の後ろ側に、メモリ領域の破壊を検出するために 0xCC を数バイト埋め込むようになっています。0xCC = 204 なので、デバッグビルドされた C ランタイムが正常にガード用の 0xCC を返していて、.NET 側では p が SizeOf(BITMAPINFOHEADER) より大きく確保されているので、本当にメモリ確保した時の未初期化のゴミを表示しているだけではないでしょうか?

     

    • 回答の候補に設定 山本春海 2011年8月23日 6:39
    • 回答としてマーク 山本春海 2011年8月26日 5:38
    2011年8月11日 1:27
  • 少なくともprintf()に正しく値が渡せていないようです。

    Win32Api.printf("data = %d, 16進数 = %x, アドレス = %p \n", *PBYTE, *PBYTE, PBYTE);
    Console.WriteLine("data = {0}, 16進数 = {0:X}, アドレス = {1:X8}", *PBYTE, (IntPtr)PBYTE);

    でアドレスが異なります。
    # 可変引数になると単純にCDECLじゃすまないですよね…。

    で、このコードで何がしたいのかはいまいちわかっていません orz

    • 回答としてマーク 山本春海 2011年8月26日 5:38
    2011年8月11日 1:19
  • 正直なところ、長いコードがその中身を説明されることなく貼り続けられているので、読むのが大変です。(というか、スルー気味です)
    一度、何をやりたいのか(目的・理想)、どういうコードを書いているのか(現状)、そして何を期待して(期待値)と現実はどうなっているか(実際の値)をきちんと説明してください。

    そうすることで、佐祐理さんが指摘していた以下のことに対する回答になるかもしれませんね。

    C++版もC#版も、このコードの目的はなんでしょう?

    ヘッダー領域だけ値を初期化して、各ピクセルについては未初期化のままです。何か画像をロードしたわけでもなく、その未初期化の値をコンソール出力してるように読み取れます。何をしたいのかわかりません。


    質問スレッドで解決した場合は、解決の参考になった投稿に対して「回答としてマーク」のボタンを押すことで、同じ問題に遭遇した別のユーザが役立つ投稿を見つけやすくなります。
    • 回答の候補に設定 山本春海 2011年8月23日 6:39
    • 回答としてマーク 山本春海 2011年8月26日 5:38
    2011年8月14日 2:09
    モデレータ

すべての返信

  • 少なくともprintf()に正しく値が渡せていないようです。

    Win32Api.printf("data = %d, 16進数 = %x, アドレス = %p \n", *PBYTE, *PBYTE, PBYTE);
    Console.WriteLine("data = {0}, 16進数 = {0:X}, アドレス = {1:X8}", *PBYTE, (IntPtr)PBYTE);

    でアドレスが異なります。
    # 可変引数になると単純にCDECLじゃすまないですよね…。

    で、このコードで何がしたいのかはいまいちわかっていません orz

    • 回答としてマーク 山本春海 2011年8月26日 5:38
    2011年8月11日 1:19
  • > Marshal.StructureToPtr(pbmi.bmiHeader, p, false);
    > byte* PBYTE = (byte*)(void*)p;
    > PBYTE += pbmi.bmiHeader.biSize;

    BITMAPINFOHEADER の先頭から、SizeOf(BITMAPINFOHEADER) 進めた場所…つまり、BITMAPINFOHEADER の終端の外側=コピーされたメモリ領域の後ろにあるゴミを表示されているのですよね?

    > 値を見ると118になるんですが、BaseClassesのほうでは204になっています。

    「BaseClasses のほう」がどこにもないのでわかりませんが、Microsoft C++ ではデバッグビルド時には確保されたメモリ領域の後ろ側に、メモリ領域の破壊を検出するために 0xCC を数バイト埋め込むようになっています。0xCC = 204 なので、デバッグビルドされた C ランタイムが正常にガード用の 0xCC を返していて、.NET 側では p が SizeOf(BITMAPINFOHEADER) より大きく確保されているので、本当にメモリ確保した時の未初期化のゴミを表示しているだけではないでしょうか?

     

    • 回答の候補に設定 山本春海 2011年8月23日 6:39
    • 回答としてマーク 山本春海 2011年8月26日 5:38
    2011年8月11日 1:27
  • コードを変更したので、全部書き込みます。

    C#側

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace Test1
    {
    
      using DWORD = System.UInt64;
      using REFERENCE_TIME = System.Int64;
      public enum BI : uint
      {
        /// <summary>
        /// 無圧縮通常形式
        /// </summary>
        BI_RGB = 0,
        /// <summary>
        /// 8bit 連長圧縮形式
        /// </summary>
        BI_RLE8 = 1,
        /// <summary>
        /// 4bit 連長圧縮形式
        /// </summary>
        BI_RLE4 = 2,
        /// <summary>
        /// 無圧縮拡張形式
        /// </summary>
        BI_BITFIELDS = 3,
        /// <summary>
        /// JPEG圧縮方式
        /// </summary>
        BI_JPEG = 4,
        /// <summary>
        /// PING圧縮方式
        /// </summary>
        BI_PNG = 5,
      };
      [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)]
      public unsafe struct BITMAPINFOHEADER
      {
    
        public int biSize;
        public int biWidth;
        public int biHeight;
        public ushort biPlanes;
        public ushort biBitCount;
        public uint biCompression;
        public uint biSizeImage;
        public int biXPelsPerMeter;
        public int biYPelsPerMeter;
        public uint biClrUsed;
        public uint biClrImportant;
        
      }
      [StructLayout(LayoutKind.Sequential, Pack = 4)]
      public struct RECT
      {
        public int left;
        public int top;
        public int right;
        public int bottom;
      }
      [StructLayout(LayoutKind.Sequential, Pack = 4)]
      public struct VIDEOINFOHEADER
      {
        public RECT rcSource;     // The bit we really want to use
        public RECT rcTarget;     // Where the video should go
        public uint dwBitRate;     // Approximate bit data rate
        public uint dwBitErrorRate;  // Bit error rate for this stream
        public REFERENCE_TIME AvgTimePerFrame;  // Average time per frame (100ns units)
    
        public BITMAPINFOHEADER bmiHeader;
    
      }
      [StructLayout(LayoutKind.Sequential, Pack = 4)]
      public struct RGBQUAD
      {
        public byte rgbBlue;
        public byte rgbGreen;
        public byte rgbRed;
        public byte rgbReserved;
      };
      [StructLayout(LayoutKind.Sequential,Pack=4)]
      public struct TRUECOLORINFO
      {
        [MarshalAs(UnmanagedType.ByValArray,/*UnmanagedType.SafeArray= UnmanagedType.U8,*/  SizeConst = 3)]
        public uint[] dwBitMasks;
        [MarshalAs(UnmanagedType.ByValArray,/*UnmanagedType.SafeArray= UnmanagedType.Struct,*/ SizeConst = 256)]
        public RGBQUAD[] bmiColors;
      };
      
      
      public static unsafe class Win32Api
      {
        [DllImport("msvcrt.dll", CharSet = CharSet.Ansi)]//, CallingConvention = CallingConvention.Cdecl)]
        public static extern int printf(string format, byte b1, byte b2, byte* b3);
        [DllImport("msvcrt.dll", CharSet = CharSet.Ansi)]//, CallingConvention = CallingConvention.Cdecl)]
        public static extern int printf(string format, byte b1, byte b2, byte* b3, byte b4);
        [DllImport("kernel32.dll")]
        public static extern unsafe void CopyMemory(void* dst, void* src, int size);
        [DllImport("msvcrt.dll", CharSet = CharSet.Ansi)]//, CallingConvention = CallingConvention.Cdecl)]
        public static extern int printf(string format, int b1, int b2, void* b3);
      }
      public unsafe class Program
      {
        
        public static unsafe TRUECOLORINFO TTRUECOLOR(VIDEOINFOHEADER pbmi)
        {
    
          // 配列をピン止めしてGCの対象から外す
          GCHandle gch = GCHandle.Alloc(pbmi.bmiHeader, GCHandleType.Pinned);
    
          // 配列の先頭のアドレスを取得
          IntPtr ptr = gch.AddrOfPinnedObject();
          byte* bptr = (byte*)(void*)ptr;
          Console.WriteLine("Value:{0} @ Address:{1:x}", *bptr, (long)bptr);
          
    
          // ポインタの加算
          ptr = new IntPtr(ptr.ToInt32() + pbmi.bmiHeader.biSize);
          bptr = (byte*)(void*)ptr;
          Console.WriteLine("Value:{0} @ Address:{1:x}", *bptr, (long)bptr);
          
          
          object o = Marshal.PtrToStructure(ptr, typeof(TRUECOLORINFO));
          TRUECOLORINFO t = (TRUECOLORINFO)o;
          
          // ピン止め解除
          gch.Free();
          return t;
    
        }
        unsafe static void Main()
        {
          
          BITMAPINFOHEADER binfoh = new BITMAPINFOHEADER();
          binfoh.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
          binfoh.biWidth = 100;
          binfoh.biHeight = 100;
          binfoh.biPlanes = 1;
          binfoh.biCompression = (uint)BI.BI_BITFIELDS;
          binfoh.biSizeImage = 0;
          binfoh.biXPelsPerMeter = 0;
          binfoh.biYPelsPerMeter = 0;
          binfoh.biClrUsed = 256;
          binfoh.biClrImportant = 0;
          VIDEOINFOHEADER v = new VIDEOINFOHEADER();
          RECT rs = new RECT(), rt = new RECT();
          rs.top = 0;
          rs.left = 0;
          rs.right = 100;
          rs.bottom = 100;
          rt.top = 0;
          rt.left = 0;
          rt.right = 100;
          rt.bottom = 100;
          v.rcSource = rs;
          v.rcTarget = rt;
          v.dwBitRate = 100;
          v.dwBitErrorRate = 10;
          v.bmiHeader = binfoh;
    
          TRUECOLORINFO tr = TTRUECOLOR(v);
          for (int i = 0; i < 256; i++)
          {
            Console.WriteLine("Red = {0} , Green = {1} , Blue = {2}, Reserved = {3}", tr.bmiColors[i].rgbRed, tr.bmiColors[i].rgbGreen, tr.bmiColors[i].rgbBlue, tr.bmiColors[i].rgbReserved);
          }
       
        }
      }
    }
    
    

    結果

    Value:40 @ Address:1222f78
    Value:0 @ Address:1222fa0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 35 , Blue = 176, Reserved = 121
    Red = 34 , Green = 47 , Blue = 120, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 68 , Blue = 200, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 7 , Blue = 64, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 1 , Green = 0 , Blue = 0, Reserved = 64
    Red = 50 , Green = 234 , Blue = 240, Reserved = 121
    Red = 0 , Green = 0 , Blue = 7, Reserved = 0
    Red = 0 , Green = 0 , Blue = 4, Reserved = 0
    Red = 0 , Green = 1 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 69 , Blue = 28, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 34 , Green = 47 , Blue = 232, Reserved = 1
    Red = 0 , Green = 1 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 62 , Blue = 108, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 53 , Blue = 148, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 7 , Blue = 64, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 49 , Blue = 120, Reserved = 121
    Red = 34 , Green = 48 , Blue = 140, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 7, Reserved = 0
    Red = 56 , Green = 81 , Blue = 236, Reserved = 63
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 50 , Blue = 116, Reserved = 121
    Red = 0 , Green = 0 , Blue = 11, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 34 , Green = 65 , Blue = 184, Reserved = 1
    Red = 34 , Green = 49 , Blue = 168, Reserved = 1
    Red = 0 , Green = 3 , Blue = 164, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 45 , Blue = 112, Reserved = 121
    Red = 0 , Green = 3 , Blue = 164, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 128
    Red = 51 , Green = 11 , Blue = 36, Reserved = 121
    Red = 0 , Green = 0 , Blue = 14, Reserved = 0
    Red = 0 , Green = 0 , Blue = 13, Reserved = 0
    Red = 111 , Green = 0 , Blue = 99, Reserved = 0
    Red = 101 , Green = 0 , Blue = 100, Reserved = 0
    Red = 97 , Green = 0 , Blue = 112, Reserved = 0
    Red = 101 , Green = 0 , Blue = 103, Reserved = 0
    Red = 46 , Green = 0 , Blue = 115, Reserved = 0
    Red = 108 , Green = 0 , Blue = 110, Reserved = 0
    Red = 0 , Green = 0 , Blue = 112, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 28 , Blue = 164, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 50 , Green = 231 , Blue = 204, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 34 , Blue = 28, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 9 , Green = 89 , Blue = 156, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 9 , Green = 89 , Blue = 156, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 60 , Green = 73 , Blue = 60, Reserved = 121
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 149 , Green = 147 , Blue = 72, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 34 , Green = 49 , Blue = 244, Reserved = 1
    Red = 34 , Green = 50 , Blue = 8, Reserved = 1
    Red = 0 , Green = 3 , Blue = 164, Reserved = 0
    Red = 1 , Green = 1 , Blue = 0, Reserved = 0
    Red = 34 , Green = 81 , Blue = 56, Reserved = 1
    Red = 34 , Green = 74 , Blue = 244, Reserved = 1
    Red = 34 , Green = 65 , Blue = 144, Reserved = 1
    Red = 34 , Green = 65 , Blue = 164, Reserved = 1
    Red = 0 , Green = 3 , Blue = 164, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 60 , Green = 90 , Blue = 112, Reserved = 121
    Red = 195 , Green = 0 , Blue = 0, Reserved = 0
    Red = 197 , Green = 0 , Blue = 0, Reserved = 0
    Red = 199 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 251 , Green = 0 , Blue = 63, Reserved = 48
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 73 , Blue = 92, Reserved = 121
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 34 , Green = 49 , Blue = 168, Reserved = 1
    Red = 34 , Green = 81 , Blue = 56, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 73 , Blue = 168, Reserved = 121
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 34 , Green = 49 , Blue = 168, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 48 , Blue = 251, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 128
    Red = 51 , Green = 11 , Blue = 36, Reserved = 121
    Red = 0 , Green = 0 , Blue = 33, Reserved = 0
    Red = 0 , Green = 0 , Blue = 32, Reserved = 0
    Red = 76 , Green = 0 , Blue = 78, Reserved = 0
    Red = 95 , Green = 0 , Blue = 83, Reserved = 0
    Red = 111 , Green = 0 , Blue = 67, Reserved = 0
    Red = 101 , Green = 0 , Blue = 100, Reserved = 0
    Red = 97 , Green = 0 , Blue = 80, Reserved = 0
    Red = 101 , Green = 0 , Blue = 103, Reserved = 0
    Red = 123 , Green = 0 , Blue = 95, Reserved = 0
    Red = 125 , Green = 0 , Blue = 48, Reserved = 0
    Red = 123 , Green = 0 , Blue = 95, Reserved = 0
    Red = 125 , Green = 0 , Blue = 49, Reserved = 0
    Red = 123 , Green = 0 , Blue = 95, Reserved = 0
    Red = 125 , Green = 0 , Blue = 50, Reserved = 0
    Red = 123 , Green = 0 , Blue = 95, Reserved = 0
    Red = 125 , Green = 0 , Blue = 51, Reserved = 0
    Red = 123 , Green = 0 , Blue = 95, Reserved = 0
    Red = 125 , Green = 0 , Blue = 52, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 55 , Blue = 32, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 34 , Green = 60 , Blue = 60, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 34 , Green = 50 , Blue = 212, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 34 , Green = 17 , Blue = 152, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 127, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 128
    Red = 51 , Green = 11 , Blue = 36, Reserved = 121
    Red = 0 , Green = 0 , Blue = 5, Reserved = 0
    Red = 0 , Green = 0 , Blue = 4, Reserved = 0
    Red = 97 , Green = 0 , Blue = 110, Reserved = 0
    Red = 101 , Green = 0 , Blue = 109, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 56 , Blue = 252, Reserved = 121
    Red = 34 , Green = 51 , Blue = 84, Reserved = 1
    Red = 34 , Green = 17 , Blue = 152, Reserved = 1
    Red = 34 , Green = 17 , Blue = 152, Reserved = 1
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 58 , Green = 43 , Blue = 84, Reserved = 121
    Red = 58 , Green = 53 , Blue = 92, Reserved = 121
    Red = 0 , Green = 0 , Blue = 127, Reserved = 0
    Red = 0 , Green = 0 , Blue = 127, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 128
    Red = 51 , Green = 11 , Blue = 36, Reserved = 121
    Red = 0 , Green = 0 , Blue = 12, Reserved = 0
    Red = 0 , Green = 0 , Blue = 11, Reserved = 0
    Red = 117 , Green = 0 , Blue = 99, Reserved = 0
    Red = 116 , Green = 0 , Blue = 108, Reserved = 0
    Red = 114 , Green = 0 , Blue = 117, Reserved = 0
    Red = 78 , Green = 0 , Blue = 101, Reserved = 0
    Red = 109 , Green = 0 , Blue = 97, Reserved = 0
    Red = 0 , Green = 0 , Blue = 101, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 128
    Red = 51 , Green = 11 , Blue = 36, Reserved = 121
    Red = 0 , Green = 0 , Blue = 12, Reserved = 0
    Red = 0 , Green = 0 , Blue = 11, Reserved = 0
    Red = 117 , Green = 0 , Blue = 99, Reserved = 0
    Red = 116 , Green = 0 , Blue = 108, Reserved = 0
    Red = 114 , Green = 0 , Blue = 117, Reserved = 0
    Red = 46 , Green = 0 , Blue = 101, Reserved = 0
    Red = 108 , Green = 0 , Blue = 110, Reserved = 0
    Red = 0 , Green = 0 , Blue = 112, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 57 , Blue = 76, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 34 , Green = 51 , Blue = 44, Reserved = 1
    Red = 57 , Green = 43 , Blue = 140, Reserved = 121
    Red = 57 , Green = 43 , Blue = 148, Reserved = 121
    Red = 57 , Green = 59 , Blue = 116, Reserved = 121
    Red = 0 , Green = 0 , Blue = 205, Reserved = 0
    Red = 0 , Green = 1 , Blue = 48, Reserved = 0
    Red = 58 , Green = 53 , Blue = 92, Reserved = 121
    Red = 0 , Green = 1 , Blue = 1, Reserved = 0
    Red = 34 , Green = 51 , Blue = 236, Reserved = 1
    Red = 34 , Green = 53 , Blue = 124, Reserved = 1
    Red = 34 , Green = 52 , Blue = 180, Reserved = 1
    Red = 57 , Green = 50 , Blue = 152, Reserved = 121
    Red = 57 , Green = 57 , Blue = 88, Reserved = 121
    Red = 57 , Green = 43 , Blue = 216, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 28 , Blue = 164, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 51 , Green = 57 , Blue = 152, Reserved = 121
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0

    C++側

    #include <windows.h>
    #include <stdio.h>
    typedef LONGLONG REFERENCE_TIME;
    #define TRUECOLOR(pbmi) ((TRUECOLORINFO *)(((LPBYTE)&((pbmi)->bmiHeader)) \
    					+ (pbmi)->bmiHeader.biSize))
    struct TRUECOLORINFO
    {
      DWORD  dwBitMasks[3];
      RGBQUAD bmiColors[256];
    } ;
    
    struct VIDEOINFOHEADER {
    
      RECT      rcSource;     // The bit we really want to use
      RECT      rcTarget;     // Where the video should go
      DWORD      dwBitRate;     // Approximate bit data rate
      DWORD      dwBitErrorRate;  // Bit error rate for this stream
      REFERENCE_TIME AvgTimePerFrame;  // Average time per frame (100ns units)
    
      BITMAPINFOHEADER bmiHeader;
    
    } ;
    
    int main()
    {
    	
    	BITMAPINFOHEADER binfoh;
    	binfoh.biSize = sizeof(BITMAPINFOHEADER);
    	binfoh.biWidth = 100;
    	binfoh.biHeight = 100;
    	binfoh.biPlanes = 1;
    	binfoh.biCompression = BI_BITFIELDS;
    	binfoh.biSizeImage = 0;
    	binfoh.biXPelsPerMeter = 0;
    	binfoh.biYPelsPerMeter = 0;
    	binfoh.biClrUsed = 256;
    	binfoh.biClrImportant = 0;
    	VIDEOINFOHEADER vinfoh;
    	RECT rs = {0,0,100,100},rt = {0,0,100,100};
    	vinfoh.rcSource = rs;
    	vinfoh.rcTarget = rt;
    	vinfoh.dwBitRate = 100;
    	vinfoh.dwBitErrorRate = 10;
    	vinfoh.bmiHeader=binfoh;
    	for(int i = 0;i<256;i++)
    	{
    		printf("Red = %d , Green = %d , Blue = %d, Reserved = %d \n", TRUECOLOR(&vinfoh)->bmiColors[i].rgbRed, TRUECOLOR(&vinfoh)->bmiColors[i].rgbGreen, TRUECOLOR(&vinfoh)->bmiColors[i].rgbBlue, TRUECOLOR(&vinfoh)->bmiColors[i].rgbReserved);
    	}
    	return 0;
    }
    

    結果

    Red = 0 , Green = 0 , Blue = 100, Reserved = 0
    Red = 0 , Green = 0 , Blue = 100, Reserved = 0
    Red = 204 , Green = 0 , Blue = 1, Reserved = 204
    Red = 0 , Green = 0 , Blue = 3, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 1 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 204 , Green = 204 , Blue = 204, Reserved = 204
    Red = 18 , Green = 255 , Blue = 184, Reserved = 0
    Red = 65 , Green = 27 , Blue = 166, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 59 , Green = 93 , Blue = 144, Reserved = 0
    Red = 59 , Green = 60 , Blue = 72, Reserved = 0
    Red = 97 , Green = 148 , Blue = 101, Reserved = 73
    Red = 40 , Green = 244 , Blue = 42, Reserved = 82
    Red = 204 , Green = 88 , Blue = 39, Reserved = 1
    Red = 253 , Green = 192 , Blue = 0, Reserved = 127
    Red = 54 , Green = 158 , Blue = 153, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 19 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 18 , Green = 255 , Blue = 124, Reserved = 0
    Red = 0 , Green = 2 , Blue = 71, Reserved = 0
    Red = 18 , Green = 255 , Blue = 224, Reserved = 0
    Red = 65 , Green = 16 , Blue = 120, Reserved = 0
    Red = 50 , Green = 1 , Blue = 237, Reserved = 73
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 18 , Green = 255 , Blue = 192, Reserved = 0
    Red = 65 , Green = 25 , Blue = 237, Reserved = 0
    Red = 18 , Green = 255 , Blue = 240, Reserved = 0
    Red = 129 , Green = 112 , Blue = 119, Reserved = 124
    Red = 40 , Green = 244 , Blue = 42, Reserved = 82
    Red = 204 , Green = 88 , Blue = 39, Reserved = 1
    Red = 253 , Green = 192 , Blue = 0, Reserved = 127
    Red = 84 , Green = 215 , Blue = 56, Reserved = 128
    Red = 18 , Green = 255 , Blue = 200, Reserved = 0
    Red = 58 , Green = 109 , Blue = 168, Reserved = 130
    Red = 255 , Green = 255 , Blue = 255, Reserved = 255
    Red = 131 , Green = 154 , Blue = 216, Reserved = 124
    Red = 129 , Green = 112 , Blue = 128, Reserved = 124
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 65 , Green = 17 , Blue = 14, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 116 , Green = 99 , Blue = 65, Reserved = 120
    Red = 0 , Green = 0 , Blue = 32, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 36 , Blue = 156, Reserved = 0
    Red = 0 , Green = 0 , Blue = 196, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 32, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 20, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 6, Reserved = 0
    Red = 0 , Green = 0 , Blue = 52, Reserved = 0
    Red = 0 , Green = 1 , Blue = 20, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 2 , Blue = 20, Reserved = 0
    Red = 0 , Green = 1 , Blue = 156, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 89 , Green = 73 , Blue = 91, Reserved = 45
    Red = 0 , Green = 3 , Blue = 176, Reserved = 0
    Red = 0 , Green = 0 , Blue = 50, Reserved = 0
    Red = 0 , Green = 3 , Blue = 228, Reserved = 0
    Red = 0 , Green = 2 , Blue = 216, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 2 , Green = 2 , Blue = 228, Reserved = 131
    Red = 0 , Green = 6 , Blue = 188, Reserved = 0
    Red = 0 , Green = 0 , Blue = 70, Reserved = 0
    Red = 0 , Green = 7 , Blue = 4, Reserved = 0
    Red = 0 , Green = 2 , Blue = 234, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 140 , Green = 213 , Blue = 210, Reserved = 209
    Red = 0 , Green = 9 , Blue = 240, Reserved = 0
    Red = 0 , Green = 0 , Blue = 70, Reserved = 0
    Red = 0 , Green = 10 , Blue = 56, Reserved = 0
    Red = 0 , Green = 2 , Blue = 234, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 106 , Green = 173 , Blue = 46, Reserved = 216
    Red = 0 , Green = 13 , Blue = 36, Reserved = 0
    Red = 0 , Green = 0 , Blue = 70, Reserved = 0
    Red = 0 , Green = 13 , Blue = 108, Reserved = 0
    Red = 0 , Green = 3 , Blue = 4, Reserved = 0
    Red = 0 , Green = 0 , Blue = 16, Reserved = 0
    Red = 0 , Green = 0 , Blue = 4, Reserved = 0
    Red = 0 , Green = 0 , Blue = 212, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 1 , Blue = 20, Reserved = 0
    Red = 0 , Green = 15 , Blue = 144, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 0 , Green = 16 , Blue = 164, Reserved = 0
    Red = 0 , Green = 3 , Blue = 44, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 4, Reserved = 0
    Red = 0 , Green = 19 , Blue = 208, Reserved = 0
    Red = 0 , Green = 16 , Blue = 80, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 0 , Green = 0 , Blue = 6, Reserved = 0
    Red = 0 , Green = 36 , Blue = 32, Reserved = 0
    Red = 0 , Green = 0 , Blue = 124, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 72 , Green = 115 , Blue = 83, Reserved = 100
    Red = 0 , Green = 0 , Blue = 44, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 5, Reserved = 0
    Red = 0 , Green = 0 , Blue = 136, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 15 , Blue = 92, Reserved = 0
    Red = 0 , Green = 0 , Blue = 44, Reserved = 0
    Red = 0 , Green = 0 , Blue = 90, Reserved = 0
    Red = 0 , Green = 0 , Blue = 90, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 0 , Green = 0 , Blue = 36, Reserved = 0
    Red = 0 , Green = 0 , Blue = 52, Reserved = 0
    Red = 58 , Green = 0 , Blue = 67, Reserved = 0
    Red = 87 , Green = 0 , Blue = 92, Reserved = 0
    Red = 78 , Green = 0 , Blue = 73, Reserved = 0
    Red = 79 , Green = 0 , Blue = 68, Reserved = 0
    Red = 83 , Green = 0 , Blue = 87, Reserved = 0
    Red = 87 , Green = 0 , Blue = 92, Reserved = 0
    Red = 110 , Green = 0 , Blue = 105, Reserved = 0
    Red = 120 , Green = 0 , Blue = 83, Reserved = 0
    Red = 92 , Green = 0 , Blue = 115, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 1 , Blue = 0, Reserved = 0
    Red = 0 , Green = 1 , Blue = 156, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 89 , Green = 73 , Blue = 91, Reserved = 45
    Red = 0 , Green = 2 , Blue = 156, Reserved = 0
    Red = 0 , Green = 0 , Blue = 50, Reserved = 0
    Red = 0 , Green = 2 , Blue = 208, Reserved = 0
    Red = 0 , Green = 2 , Blue = 216, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 2 , Green = 2 , Blue = 228, Reserved = 131
    Red = 0 , Green = 5 , Blue = 168, Reserved = 0
    Red = 0 , Green = 0 , Blue = 70, Reserved = 0
    Red = 0 , Green = 5 , Blue = 240, Reserved = 0
    Red = 0 , Green = 2 , Blue = 234, Reserved = 0
    Red = 0 , Green = 0 , Blue = 3, Reserved = 0
    Red = 140 , Green = 213 , Blue = 210, Reserved = 209
    Red = 0 , Green = 8 , Blue = 220, Reserved = 0
    Red = 0 , Green = 0 , Blue = 70, Reserved = 0
    Red = 0 , Green = 9 , Blue = 36, Reserved = 0
    Red = 0 , Green = 2 , Blue = 234, Reserved = 0
    Red = 0 , Green = 0 , Blue = 4, Reserved = 0
    Red = 106 , Green = 173 , Blue = 46, Reserved = 216
    Red = 0 , Green = 12 , Blue = 16, Reserved = 0
    Red = 0 , Green = 0 , Blue = 70, Reserved = 0
    Red = 0 , Green = 12 , Blue = 88, Reserved = 0
    Red = 0 , Green = 3 , Blue = 4, Reserved = 0
    Red = 0 , Green = 0 , Blue = 5, Reserved = 0
    Red = 0 , Green = 0 , Blue = 100, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 1 , Blue = 10, Reserved = 0
    Red = 0 , Green = 1 , Blue = 100, Reserved = 0
    Red = 0 , Green = 0 , Blue = 2, Reserved = 0
    Red = 0 , Green = 0 , Blue = 44, Reserved = 0
    Red = 0 , Green = 2 , Blue = 110, Reserved = 0
    Red = 237 , Green = 115 , Blue = 92, Reserved = 39
    Red = 203 , Green = 211 , Blue = 232, Reserved = 1
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 1, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 0 , Green = 0 , Blue = 0, Reserved = 0
    Red = 105 , Green = 0 , Blue = 77, Reserved = 0
    Red = 114 , Green = 0 , Blue = 99, Reserved = 0
    Red = 115 , Green = 0 , Blue = 111, Reserved = 0
    Red = 102 , Green = 0 , Blue = 111, Reserved = 0
    Red = 46 , Green = 0 , Blue = 116, Reserved = 0
    Red = 105 , Green = 0 , Blue = 87, Reserved = 0
    Red = 100 , Green = 0 , Blue = 110, Reserved = 0
    Red = 119 , Green = 0 , Blue = 111, Reserved = 0
    Red = 46 , Green = 0 , Blue = 115, Reserved = 0
    Red = 121 , Green = 0 , Blue = 83, Reserved = 0
    Red = 116 , Green = 0 , Blue = 115, Reserved = 0
    Red = 109 , Green = 0 , Blue = 101, Reserved = 0
    Red = 111 , Green = 0 , Blue = 67, Reserved = 0
    Red = 112 , Green = 0 , Blue = 109, Reserved = 0
    Red = 116 , Green = 0 , Blue = 97, Reserved = 0
    Red = 98 , Green = 0 , Blue = 105, Reserved = 0
    Red = 101 , Green = 0 , Blue = 108, Reserved = 0
    Red = 112 , Green = 0 , Blue = 44, Reserved = 0
    Red = 111 , Green = 0 , Blue = 114, Reserved = 0
    Red = 101 , Green = 0 , Blue = 99, Reserved = 0
    Red = 115 , Green = 0 , Blue = 115, Reserved = 0
    Red = 114 , Green = 0 , Blue = 111, Reserved = 0
    Red = 114 , Green = 0 , Blue = 65, Reserved = 0
    Red = 104 , Green = 0 , Blue = 99, Reserved = 0
    Red = 116 , Green = 0 , Blue = 105, Reserved = 0
    Red = 99 , Green = 0 , Blue = 101, Reserved = 0
    Red = 117 , Green = 0 , Blue = 116, Reserved = 0
    Red = 101 , Green = 0 , Blue = 114, Reserved = 0
    Red = 34 , Green = 0 , Blue = 61, Reserved = 0
    Red = 56 , Green = 0 , Blue = 120, Reserved = 0
    Red = 34 , Green = 0 , Blue = 54, Reserved = 0
    Red = 112 , Green = 0 , Blue = 44, Reserved = 0
    Red = 98 , Green = 0 , Blue = 117, Reserved = 0
    Red = 105 , Green = 0 , Blue = 108, Reserved = 0
    Red = 75 , Green = 0 , Blue = 99, Reserved = 0
    Red = 121 , Green = 0 , Blue = 101, Reserved = 0
    Red = 111 , Green = 0 , Blue = 84, Reserved = 0
    Red = 101 , Green = 0 , Blue = 107, Reserved = 0
    Red = 61 , Green = 0 , Blue = 110, Reserved = 0
    Red = 54 , Green = 0 , Blue = 34, Reserved = 0
    Red = 57 , Green = 0 , Blue = 53, Reserved = 0
    Red = 98 , Green = 0 , Blue = 53, Reserved = 0
    Red = 52 , Green = 0 , Blue = 54, Reserved = 0
    Red = 52 , Green = 0 , Blue = 49, Reserved = 0
    Red = 99 , Green = 0 , Blue = 52, Reserved = 0
    Red = 102 , Green = 0 , Blue = 99, Reserved = 0
    Red = 100 , Green = 0 , Blue = 49, Reserved = 0
    Red = 34 , Green = 0 , Blue = 102, Reserved = 0
    Red = 116 , Green = 0 , Blue = 44, Reserved = 0
    Red = 112 , Green = 0 , Blue = 121, Reserved = 0

    以上のように値が変わってしまいます。どなたかご教示ください。

    2011年8月11日 13:07
  • C++版もC#版も、このコードの目的はなんでしょう?

    ヘッダー領域だけ値を初期化して、各ピクセルについては未初期化のままです。何か画像をロードしたわけでもなく、その未初期化の値をコンソール出力してるように読み取れます。何をしたいのかわかりません。

    2011年8月11日 15:16
  • コードを変更したので、全部書き込みます。

    using System;
    using System.Collections.Generic;
    using System.Text;
    using DexterLib;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Runtime.Remoting;
    using System.Diagnostics;
    using System.IO;
    using REFERENCE_TIME = System.Int64;
    namespace Test
    {
      [StructLayout( LayoutKind.Sequential,Pack=4)]
      public struct RGBQUAD
      {
        public byte rgbBlue;
        public byte rgbGreen;
        public byte rgbRed;
        public byte rgbReserved;
      };
      [StructLayout( LayoutKind.Sequential,Pack=4)]
      public struct RECT
      {
        public int left;
        public int top;
        public int right;
        public int bottom;
      }
      [StructLayout(LayoutKind.Sequential,Pack=4)]
      public struct VIDEOINFOHEADER
      {
        public RECT rcSource;     // The bit we really want to use
        public RECT rcTarget;     // Where the video should go
        public uint dwBitRate;     // Approximate bit data rate
        public uint dwBitErrorRate;  // Bit error rate for this stream
        public REFERENCE_TIME AvgTimePerFrame;  // Average time per frame (100ns units)
    
        public BITMAPINFOHEADER bmiHeader;
    
      }
      public enum BI : uint
      {
        /// <summary>
        /// 無圧縮通常形式
        /// </summary>
        BI_RGB = 0,
        /// <summary>
        /// 8bit 連長圧縮形式
        /// </summary>
        BI_RLE8 = 1,
        /// <summary>
        /// 4bit 連長圧縮形式
        /// </summary>
        BI_RLE4 = 2,
        /// <summary>
        /// 無圧縮拡張形式
        /// </summary>
        BI_BITFIELDS = 3,
        /// <summary>
        /// JPEG圧縮方式
        /// </summary>
        BI_JPEG = 4,
        /// <summary>
        /// PING圧縮方式
        /// </summary>
        BI_PNG = 5,
      };
      [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)]
      public struct BITMAPINFOHEADER
      {
    
        public int biSize;
        public int biWidth;
        public int biHeight;
        public ushort biPlanes;
        public ushort biBitCount;
        public uint biCompression;
        public uint biSizeImage;
        public int biXPelsPerMeter;
        public int biYPelsPerMeter;
        public uint biClrUsed;
        public uint biClrImportant;
        
      }
      
      [StructLayout(LayoutKind.Sequential)]
      public struct TRUECOLORINFO
      {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
        public uint[] dwBitMasks;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
        public RGBQUAD[] bmiColors;
      };
      class TestMediaDetClass
      {
        public static readonly Guid MEDIATYPE_Video = new Guid("73646976-0000-0010-8000-00aa00389b71");
        public static readonly Guid MEDIASUBTYPE_RGB32 = new Guid("e436eb7e-524f-11ce-9f53-0020af0ba770");
        public static readonly Guid MEDIATYPE_Audio = new Guid("73647561-0000-0010-8000-00aa00389b71");
        public static readonly Guid MEDIASUBTYPE_PCM = new Guid("00000001-0000-0010-8000-00AA00389B71");
        MediaDetClass mdc = new MediaDetClass();
        MediaDet pDet = null;
        public unsafe TRUECOLORINFO TRUECOLOR(string filename)
        {
          pDet = (MediaDet)mdc;
          pDet.Filename = filename;
          int Streams = pDet.OutputStreams;
          _AMMediaType am = pDet.StreamMediaType;
          if (am.majortype == MEDIATYPE_Video)
            Console.WriteLine("true");
    
          VIDEOINFOHEADER videoHeader = (VIDEOINFOHEADER)Marshal.PtrToStructure(am.pbFormat, typeof(VIDEOINFOHEADER));
    
          // 配列をピン止めしてGCの対象から外す
          GCHandle gch = GCHandle.Alloc(videoHeader.bmiHeader, GCHandleType.Pinned);
    
          // 配列の先頭のアドレスを取得
          IntPtr ptr = gch.AddrOfPinnedObject();
          Console.WriteLine("Value:{0} @ Address:{1:x}", (byte)ptr, ptr);
          byte* bptr = (byte*)(void*)ptr;
          Console.WriteLine("Value:{0} @ Address:{1:x}", *bptr, (long)bptr);
    
          // ポインタの加算
          ptr = new IntPtr(ptr.ToInt32() + videoHeader.bmiHeader.biSize);
          bptr = (byte*)(void*)ptr;
          Console.WriteLine("Value:{0} @ Address:{1:x}", *bptr, (long)bptr);
    
    
          object o = Marshal.PtrToStructure(ptr, typeof(TRUECOLORINFO));
          TRUECOLORINFO t = (TRUECOLORINFO)o;
    
          // ピン止め解除
          gch.Free();
          return t;
    
        }
      }
      
      public unsafe class Program
      {
        unsafe static void Main()
        {
          TestMediaDetClass tmdc = new TestMediaDetClass();
          TRUECOLORINFO tr = tmdc.TRUECOLOR("ruby.avi");
          /*TRUECOLORINFO tr = TTRUECOLOR(v);
          for (int i = 0; i < 256; i++)
          {
            Console.WriteLine("Red = {0} , Green = {1} , Blue = {2}, Reserved = {3}", tr.bmiColors[i].rgbRed, tr.bmiColors[i].rgbGreen, tr.bmiColors[i].rgbBlue, tr.bmiColors[i].rgbReserved);
          }*/
    
        }
      }
    }
    
    


    以上のようにした結果

    true

    Value:100 @ Address:19029604

    Value:40 @ Address:1225e64

    Value:0 @ Address:1225e8c

    となっていて

    Microsoft DirectX 9.0 SDKのサンプルのSampGrabCBのコードの一部をへんこうして

    値とアドレスを表示させた結果

    Grabbing samples from ruby.avi.

    Value:40 @ Addres:001791C0

    Value:5 @ Addres:001791E8

    となってます。

    C#側で、どのように変更したらよいのでしょうか。

    なんども質問してすいません。

     

     

    2011年8月14日 0:09
  • 日本語に不自由していて返信が読めないのでしょうか? それとも質問することで自己満足し、それで完結しているのでしょうか?
    2011年8月14日 1:57
  • 正直なところ、長いコードがその中身を説明されることなく貼り続けられているので、読むのが大変です。(というか、スルー気味です)
    一度、何をやりたいのか(目的・理想)、どういうコードを書いているのか(現状)、そして何を期待して(期待値)と現実はどうなっているか(実際の値)をきちんと説明してください。

    そうすることで、佐祐理さんが指摘していた以下のことに対する回答になるかもしれませんね。

    C++版もC#版も、このコードの目的はなんでしょう?

    ヘッダー領域だけ値を初期化して、各ピクセルについては未初期化のままです。何か画像をロードしたわけでもなく、その未初期化の値をコンソール出力してるように読み取れます。何をしたいのかわかりません。


    質問スレッドで解決した場合は、解決の参考になった投稿に対して「回答としてマーク」のボタンを押すことで、同じ問題に遭遇した別のユーザが役立つ投稿を見つけやすくなります。
    • 回答の候補に設定 山本春海 2011年8月23日 6:39
    • 回答としてマーク 山本春海 2011年8月26日 5:38
    2011年8月14日 2:09
    モデレータ
  • こんにちは、馬鹿1号 さん。

    MSDN フォーラムのご利用ありがとうございます。オペレーターの山本です。

    他の方からもアドバイスいただいているように、必要以上にサンプル コード等が長くなることで、問題が分かりにくくなり、期待したような返答が付きにくくなることがあるかと思います。
    もし、まだ問題を解決されていないのであれば、皆さんからのアドバイスを参考に、質問内容を整理して、必要最小限のコードを説明文とともに新規スレッドの投稿をお願いいたしますね。
    その際には、必要に応じてこちらのスレッドのリンクを付けるなどしてください。

    誠に恐れ入りますが、こちらのスレッドは終了させていただきますね。

    今後とも、MSDN フォーラムをよろしくお願いいたします。
                                                                 
    日本マイクロソフト株式会社 フォーラム オペレーター 山本 春海

    2011年8月26日 5:37