在c#代码中使用W3BTRV7.DLL BTrieve

时间:2015-10-30 15:01:07

标签: c# btrieve

我正在寻找一个简短的示例,使用c#代码中的W3BTRV7.DLL直接访问BTrieve 6.15文件。

感谢任何sugestions

1 个答案:

答案 0 :(得分:2)

这是一个示例:

[System.Runtime.InteropServices.DllImport("WBTRV32.dll", CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
    static extern short BTRCALL(ushort operation,
    [System.Runtime.InteropServices.MarshalAs  (System.Runtime.InteropServices.UnmanagedType.LPArray, SizeConst = 128)] byte[] posBlk,
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Struct, SizeConst = 255)]
    ref RecordBuffer databuffer,
    ref int dataLength,
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPArray, SizeConst = 255)] char[] keyBffer,
    ushort keyLength, ushort keyNum);

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1, CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
    public struct RecordBuffer
    {
        public short docType;
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 2500)]
        public char[] docDescPlural;
        public short sorting;
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 2500)]
        public char[] docDescSingle;
        public short copyOtherThanSrc;
        public double defaultNotebookNo;
    }

private void PopulateAllRecords(string fileName)
    {
        byte[] positionBlock = new byte[128];
        char[] fileNameArray = fileName.ToCharArray();

        // Open file
        RecordBuffer dataBuffer = new RecordBuffer();
        int bufferLength = System.Runtime.InteropServices.Marshal.SizeOf(dataBuffer);
        short status = (short)BTRCALL((ushort)OPCODE.BOPEN, positionBlock, ref dataBuffer, ref bufferLength, fileNameArray, 0, 0);

        if (status == 0)
        {
         .....
         }
   }