IStream オブジェクト (System.Runtime.InteropServices.ComTypes.IStream) を返すサードパーティ コンポーネントを使用しています。その IStream のデータを取得してファイルに書き込む必要があります。私はそれを成し遂げることができましたが、コードにはあまり満足していません.
「strm」が私のIStreamであるため、これが私のテストコードです...
// access the structure containing statistical info about the stream
System.Runtime.InteropServices.ComTypes.STATSTG stat;
strm.Stat(out stat, 0);
System.IntPtr myPtr = (IntPtr)0;
// get the "cbSize" member from the stat structure
// this is the size (in bytes) of our stream.
int strmSize = (int)stat.cbSize; // *** DANGEROUS *** (long to int cast)
byte[] strmInfo = new byte[strmSize];
strm.Read(strmInfo, strmSize, myPtr);
string outFile = @"c:\test.db3";
File.WriteAllBytes(outFile, strmInfo);
少なくとも、上記のように long から int へのキャストは好きではありませんが、上記よりも元のストリームの長さを取得するためのより良い方法はないのでしょうか? 私はC#に少し慣れていないので、ポインタに感謝します。