2

次のように C# からメソッドを呼び出しています。

[DllImport(@"pHash.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ph_dct_videohash(string file, ref int length);

そして、ここに私がライブラリから呼び出しているメソッドがあります

ulong64* ph_dct_videohash(const char *filename, int &Length){

    CImgList<uint8_t> *keyframes = ph_getKeyFramesFromVideo(filename);
    if (keyframes == NULL)
        return NULL;

    Length = keyframes->size();

    ulong64 *hash = (ulong64*)malloc(sizeof(ulong64)*Length);
    //some code to fill the hash array
    return hash;
}

ulongから配列を読み取るにはどうすればよいIntPtrですか?

4

2 に答える 2

2

安全でないコードを使用することを検討してください。

IntPtr pfoo = ph_dct_videohash(/* args */);
unsafe {
    ulong* foo = (ulong*)pfoo;
    ulong value = *foo;
    Console.WriteLine(value);
}
于 2015-07-10T20:59:22.810 に答える