2015-10-30 18 views
-4

我正在尋找一個簡短的示例,直接訪問使用W3BTRV7.DLL在c#代碼中的BTrieve 6.15文件。使用W3BTRV7.DLL在c#代碼中的BUFF

感謝您的任何sugestions

+1

這不是一個樣本提供服務,這是一個代碼,幫助服務。我們幫助現有的代碼,而不是按需創建教程。 –

+0

查看Btrieve SDK。如果您使用6.15,您將被限制爲32位C#。 Pervasive的網站上有一個樣本,但是它適用於更高版本的Btrieve。 – mirtheil

回答

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) 
     { 
     ..... 
     } 
    }