如何元帅 - C#
我对元帅和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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论