如何元帅 - C#

发布于 2025-01-22 13:26:33 字数 2080 浏览 2 评论 0原文

我对元帅和C#感到困惑。我不明白如何将代码更改为元帅的班级。这就是我当前的代码的样子。

IntPtr pBarcodesRaw = IntPtr.Zero;
retVal = LeadTools13Imports.L_BarCodeRead( handle, null, // null to scan whole image                                                 (uint)barcodeTypes,
                         LeadTools13Imports.BARCODE_SCANLINES_PER_PIXELS,LeadTools13Imports.BARCODE_MARKERS,                                                                        1, //this parameter control if read the first bar code or all the bar codes.   0= first and 1 =                            all.
_barcodeReaderParams,IntPtr.Zero,
null,
out pBarcodesRaw );

铅工具是第三方库。

这仅用于读取第一个条形码和停止,该条形码将其编码为Bar Codedata的单个实例。现在,我必须阅读页面上的所有条形码。

if LeadTools13Imports.SUCCESS == retVal )
{  // extract the barcode read
    barcodeData = (LeadTools13Imports.BARCODEDATA)Marshal.PtrToStructure( 
                        pBarcodesRaw,
                        typeof( LeadTools13Imports.BARCODEDATA ) 
    );
}

条形码数据类看起来像这样:

[StructLayout(LayoutKind.Sequential)]
internal class BARCODEDATA
{
    internal Int32  nGroup = 0; // used only for CodeOne and PDF417

    internal UInt32 ulType = 0;

    internal Int32  nUnits = 0;

    internal RECT   rcBarLocation = new RECT();
    
    internal Int32  nSizeofBarCodeData = 0;

    [MarshalAs( UnmanagedType.LPStr )]
    internal String pszBarCodeData = "";

    internal Int32  nIndexDuplicate = 0; // for reading only

    internal Int32  nTotalCount = 0; // for reading only

    internal Int32  nDupCount = 0; // for reading only
}

我添加了此类,

[StructLayout(LayoutKind.Sequential)]
internal class BarCodeArray
{
    [MarshalAs(UnmanagedType.ByValArray , ArraySubType = UnmanagedType.Struct , SizeConst = 2)]

    public BARCODEDATA[] _barcodes;
}

我很难理解如何将此代码线更改

barcodeData = (LeadTools13Imports.BARCODEDATA)Marshal.PtrToStructure( 
    pBarcodesRaw,
    typeof( LeadTools13Imports.BARCODEDATA ) );

为元帅,以添加到barocodedata []

I am kind of confused by Marshal and C#. I don't understand how to make a code change to marshal to an Array of Class. This is what my current code looks like.

IntPtr pBarcodesRaw = IntPtr.Zero;
retVal = LeadTools13Imports.L_BarCodeRead( handle, null, // null to scan whole image                                                 (uint)barcodeTypes,
                         LeadTools13Imports.BARCODE_SCANLINES_PER_PIXELS,LeadTools13Imports.BARCODE_MARKERS,                                                                        1, //this parameter control if read the first bar code or all the bar codes.   0= first and 1 =                            all.
_barcodeReaderParams,IntPtr.Zero,
null,
out pBarcodesRaw );

Lead tools is a third party library.

This use to only read the first bar code and stop which was marshalling to a single instance of BarCodeData. Now I have to read all the bar codes on a page.

if LeadTools13Imports.SUCCESS == retVal )
{  // extract the barcode read
    barcodeData = (LeadTools13Imports.BARCODEDATA)Marshal.PtrToStructure( 
                        pBarcodesRaw,
                        typeof( LeadTools13Imports.BARCODEDATA ) 
    );
}

The bar code data class looks like this:

[StructLayout(LayoutKind.Sequential)]
internal class BARCODEDATA
{
    internal Int32  nGroup = 0; // used only for CodeOne and PDF417

    internal UInt32 ulType = 0;

    internal Int32  nUnits = 0;

    internal RECT   rcBarLocation = new RECT();
    
    internal Int32  nSizeofBarCodeData = 0;

    [MarshalAs( UnmanagedType.LPStr )]
    internal String pszBarCodeData = "";

    internal Int32  nIndexDuplicate = 0; // for reading only

    internal Int32  nTotalCount = 0; // for reading only

    internal Int32  nDupCount = 0; // for reading only
}

I added this class

[StructLayout(LayoutKind.Sequential)]
internal class BarCodeArray
{
    [MarshalAs(UnmanagedType.ByValArray , ArraySubType = UnmanagedType.Struct , SizeConst = 2)]

    public BARCODEDATA[] _barcodes;
}

I am having a hard time understanding how do i change this line of code

barcodeData = (LeadTools13Imports.BARCODEDATA)Marshal.PtrToStructure( 
    pBarcodesRaw,
    typeof( LeadTools13Imports.BARCODEDATA ) );

to marshal to an array of BARCODEDATA[]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文