Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Marshal C# struct array?
    primarykey
    data
    text
    <p>I’m developing a fingerprint login for a HRM system. Sample code given with the SDK allows verifying with one template. Here is the segment of the code. </p> <pre><code> BSTypes.ABS_BIR ppEnrolledTemplate; //Load the template array to ppEnrolledTemplate IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ppEnrolledTemplateArray[i])); Marshal.StructureToPtr(ppEnrolledTemplateArray[i], ptr, false); res = BSApi.ABSVerify(conn, ref op, 1, ref ptr, ref matching_slot, 0); </code></pre> <p>According to the SDK documentation(<a href="http://imageshack.us/photo/my-images/90/fingercapture.png/" rel="nofollow">Link</a>) ABSVerify method allows to input template array as one of the parameters. <strong>I’m finding difficulties marshaling ABS_BIR struct array.</strong> Here is the struct for ABS_BIR.</p> <pre><code> [StructLayout(LayoutKind.Sequential)] public struct ABS_BIR { public ABS_BIR_HEADER Header; // BIR header [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2560)] public byte[] Data; // The data composing the fingerprint template. } </code></pre> <p>This is the solution I came with. I wrote a method called ReadyTemplate()</p> <pre><code>private void readTemplate() { //read template from binary file for (int i = 0; i &lt; 4; i++) { FileStream objFileStream; BinaryReader objBinaryReader; try { // ========== Updated by bubz ============ byte[] data; objFileStream = new FileStream(i + ".bin", FileMode.Open); objBinaryReader = new BinaryReader(objFileStream); data = objBinaryReader.ReadBytes((int)objFileStream.Length); GCHandle pinnedData = GCHandle.Alloc(data, GCHandleType.Pinned); ppEnrolledTemplateArray[i] = (BSTypes.ABS_BIR)Marshal.PtrToStructure(pinnedData.AddrOfPinnedObject(), typeof(BSTypes.ABS_BIR)); displayOut(0, 0, "Template retrieved from PC."); displayOut(0, 0, i.ToString()); objBinaryReader.Close(); // ============ end ==================== } catch (FileNotFoundException FileEx) { displayOut(2, 0, FileEx.Message); return; } catch (Exception Ex) { displayOut(2, 0, Ex.Message); return; } } } </code></pre> <p>Please help me.Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload