Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在VB.NET/C#中成功使用cpp dll中的结构和嵌套结构?_C#_Vb.net_Dll_Structure_Marshalling - Fatal编程技术网

如何在VB.NET/C#中成功使用cpp dll中的结构和嵌套结构?

如何在VB.NET/C#中成功使用cpp dll中的结构和嵌套结构?,c#,vb.net,dll,structure,marshalling,C#,Vb.net,Dll,Structure,Marshalling,我想调用一个需要一个结构的DLL函数,该结构中有另一个结构。Dll应该将值返回到我的结构,但我只得到错误代码。有一次(以前的一些代码)我在函数调用中成功地返回了“True”,但在我的结构中没有值 我不太熟悉编组等,但如果有人能提供一个如何做到这一点的例子 Dll代码如下所示: <DllImport("ScorpionDLL.dll", CallingConvention:=CallingConvention.StdCall)> Public Shared Function bXa

我想调用一个需要一个结构的DLL函数,该结构中有另一个结构。Dll应该将值返回到我的结构,但我只得到错误代码。有一次(以前的一些代码)我在函数调用中成功地返回了“True”,但在我的结构中没有值

我不太熟悉编组等,但如果有人能提供一个如何做到这一点的例子

Dll代码如下所示:

  <DllImport("ScorpionDLL.dll", CallingConvention:=CallingConvention.StdCall)>
Public Shared Function bXaarScorpionGetPrintDataParametersUpdated(ByRef UDataParams As UpdatedPrintDataParameters) As IntPtr
End Function

第一个结构:

struct UpdatedPrintDataParameters
{
struct PrintDataParameters OriginalParameters;
DWORD RowTrailChannels[MAXROWS];        // The number of unused channels at end of print head per row
DWORD RowLeadChannels[MAXROWS];         // The number of unused channels at start of print head per row
DWORD CopyCount[MAXROWS];               // The number of repeated copies
DWORD XPMSEPDSetup[4];                  // XPM - bits to control shaft encoder and product detect configuration 
DWORD PDFilter;                         // XPM - Product Detect Filter, pass value through
DWORD Spare[13];                        // Spare
   <System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet:=CharSet.Auto)>
Public Structure UpdatedPrintDataParameters

    '''PrintDataParameters
    Public OriginalParameters As PrintDataParameters

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public RowTrailChannels() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public RowLeadChannels() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public CopyCount() As UInteger

    '''DWORD[4]
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=4, ArraySubType:=System.Runtime.InteropServices.UnmanagedType.U4)>
    Public XPMSEPDSetup() As UInteger

    '''DWORD->unsigned int
    Public PDFilter As UInteger

    '''DWORD[13]
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=13, ArraySubType:=System.Runtime.InteropServices.UnmanagedType.U4)>
    Public Spare() As UInteger
    '7
End Structure
这是第二个结构:

struct PrintDataParameters
{
// Head Setup parameters
DWORD Head;                             // This printhead number
DWORD HeadType;                         // Code indicating type of printhead connected
DWORD HeadIndex[MAXROWS];               // The index of the printhead in the array of actually connected printhead
DWORD NumberOfRows;                     // The number of rows on the printhead
DWORD SeparateRows;                     // If true, treat each row as an individual head
DWORD ImageLength[MAXROWS];             // The number of strokes in an image
DWORD ImageSize[MAXROWS];               // The number of bytes in an image
DWORD ProductOffset;                    // Number of strokes of Offset after the product and before the print starts
DWORD InterGap;                         // Gap used between continuous prints
DWORD FirstSwatheBlock;                 // The memory address where 1st swathe control block is stored
DWORD SwatheBlock;                      // The memory address to store this particular swathe control block
DWORD ThisSwathe;                       // The number of the active swathe
DWORD NextSwatheBlock;                  // The memory address where the next swathe block will be stored
DWORD MemoryBlock[MAXROWS];             // The memory address to store this image block
DWORD FirstMemoryBlock[MAXROWS];        // The memory address where 1st image swathe is stored
DWORD MemoryBlocksNeeded[MAXROWS];      // The number of memory blocks needed to store the image swathe
DWORD PreLoadSwatheBlock;               // The number of memory blocks that the pre-load strokes requires
DWORD PrintMode;                        // The print mode e.g. single shot etc.
bool  PrintOnce;                        // If true only one complete print is required
DWORD CycleMode;                        // Cycle Mode (e.g. set to PIXELMODE, CYCLEMODE)
bool ForwardBuffer;                     // Print direction i.e. forward or reverse
DWORD StartDir[MAXROWS];                // The starting head direction bit for each row 
DWORD DirBlock;                         // The direction to use for this swathe

// System setup parameters
DWORD SubPixelDivide;                   // The subpixel divide value
DWORD SaveSubPixelOffset[2][MAXROWS];   // The subpixeloffsets to use, 1st index is for forward or reverse offsets, 2nd index = row
DWORD SubPixelOffset;                   // The sub pixel offset to use for this swathe
DWORD EncoderDivide;                    // A copy of the encoder divide

// Image control parameters
DWORD TrailChannels;                    // The number of unused channels at end of print head - same value currently used for both rows, max 31
DWORD LeadChannels;                     // The number of unused channels at start of print head - same value currently used for both rows, max 31
DWORD DataChannels;                     // The total number of printing channels
DWORD HeadChannels;                     // The number of printing channels per side
bool BufferReverse[MAXROWS];            // The direction to read the data from the image buffer eg for 760, [0] = true, [1] = false
DWORD NibbleControl[MAXROWS];           // For each row defines if the even/odd/both nibbles of image data is used for printing
DWORD NibbleIndex;                      // Used to defines if we are using row 1 or row 2
DWORD LoopCount;                        // Set this to 1

LPSTR lpDIBBits;                        // Pointer to the bitmap in (screen) memory
DWORD TotalImageWidth[MAXROWS];         // The total width of the image
DWORD BitDifference;                    // The number of bits to store .... this needs to be set to 4

// Swathe control parameters
DWORD NumberSwathes[MAXROWS];           // The number of swathes to print entire image
DWORD SwatheMemoryCount[MAXROWS];       // The total number of swathes that will fit into memory for this head
DWORD StoredSwathes[MAXROWS];           // The total number of swathes that have been stored to the XUSB box
DWORD PreviousPrintSwathe[MAXROWS];     // The number of the previous swathe that was stored
bool AllSwathesFit[MAXROWS];            // True if all the swathes fit in memory at once
bool Binary;                            // True if binary or false if greyscale head?
DWORD GreyLevel;                        // The number of grey levels
bool FirstSwathe[MAXROWS];              // This should be set to true for each row for the 1st swathe of a print (doesn't need to be set again for repeat print swathes)
bool LastSwathe[MAXROWS];               // This should be set for last swathe - specifies if the image is only required to be printed once
bool LastSwatheInMemory[MAXROWS];       // This indicates that this swathe is at the end of the swathe memory
DWORD SendID[MAXROWS];                  // Id of the swathe that has been setup for sending to xusb box
bool BiPrintKeepOdd;                    // Defines if, when in bi-directional printing the number of swathes are rounded up

// These 2 values are used when a print head is only required to print part of an image
DWORD SwatheStartIndex;                 // The offset into the swathe to start printing from
DWORD SwatheIncrement;                  // The amount to add to locate the next swathe

DWORD SourceStrokeWidth;                // The number of blocks required for each image stroke

// print parameters
DWORD PrintTransportMode;               // Used to determine if bi-directional printing is required
bool bReverseSwatheOrder;               // Define if the 1st or last swathe should be printed first
bool bReverseImageOrder;                // Specify if the 1st or last stroke of the image is printed first
bool bPaletteRemap;                     // True if palette remap required
bool bBinaryBackgroundInvert;           // Invert the background for a binary image
DWORD SaveProductOffset[2][MAXROWS];    // 1st index if to forward or reverse offsets
bool bSelectHead[MAXROWS];              // This printhead is selected for print

DWORD GuardValue;                       // Set guard channels to this value

DWORD SEPDSetup;                        // Bits to control SE and PD configuration. Effectively the ID of the shaftencoder/product detect pair
bool Enable2Bit;                        // True if 2 bit mode is enabled
BYTE SysClock;                          // Encoder mode i.e. Internal, external or absolute
BYTE VLDPHCount;                        // The number of 16 nozzle VLDPH print units
BYTE Spare;                             // Spare

我的VB.Net声明如下所示:

  <DllImport("ScorpionDLL.dll", CallingConvention:=CallingConvention.StdCall)>
Public Shared Function bXaarScorpionGetPrintDataParametersUpdated(ByRef UDataParams As UpdatedPrintDataParameters) As IntPtr
End Function

公共共享函数bXaarScorpionGetPrintDataParametersUpdated(ByRef UDataParams作为UpdatedPrintDataParameters)作为IntPtr
端函数
第一个结构:

struct UpdatedPrintDataParameters
{
struct PrintDataParameters OriginalParameters;
DWORD RowTrailChannels[MAXROWS];        // The number of unused channels at end of print head per row
DWORD RowLeadChannels[MAXROWS];         // The number of unused channels at start of print head per row
DWORD CopyCount[MAXROWS];               // The number of repeated copies
DWORD XPMSEPDSetup[4];                  // XPM - bits to control shaft encoder and product detect configuration 
DWORD PDFilter;                         // XPM - Product Detect Filter, pass value through
DWORD Spare[13];                        // Spare
   <System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet:=CharSet.Auto)>
Public Structure UpdatedPrintDataParameters

    '''PrintDataParameters
    Public OriginalParameters As PrintDataParameters

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public RowTrailChannels() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public RowLeadChannels() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public CopyCount() As UInteger

    '''DWORD[4]
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=4, ArraySubType:=System.Runtime.InteropServices.UnmanagedType.U4)>
    Public XPMSEPDSetup() As UInteger

    '''DWORD->unsigned int
    Public PDFilter As UInteger

    '''DWORD[13]
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=13, ArraySubType:=System.Runtime.InteropServices.UnmanagedType.U4)>
    Public Spare() As UInteger
    '7
End Structure

公共结构UpdatedPrintDataParameters
''PrintDataParameters
公共原始参数作为PrintDataParameters
''德沃德[]
公共行TrailChannel()作为UInteger
''德沃德[]
Public rowLeadChannel()作为UInteger
''德沃德[]
公共CopyCount()作为UInteger
''德沃德[4]
将XPMSEPDSetup()作为UInteger公开
''DWORD->无符号整数
公共PDFilter作为UInteger
''德沃德[13]
公用备件()作为UInteger
'7
端部结构
第二结构

<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet:=CharSet.Auto, Size:=66)>
Public Structure PrintDataParameters
    '''DWORD->unsigned int
    Public Head As UInteger

    '''DWORD->unsigned int
    Public HeadType As UInteger

    '''DWORD[]
    <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=2)> Public HeadIndex() As UInteger

    '''DWORD->unsigned int
    Public NumberOfRows As UInteger

    '''DWORD->unsigned int
    Public SeparateRows As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public ImageLength() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public ImageSize() As UInteger

    '''DWORD->unsigned int
    Public ProductOffset As UInteger

    '''DWORD->unsigned int
    Public InterGap As UInteger

    '''DWORD->unsigned int
    Public FirstSwatheBlock As UInteger

    '''DWORD->unsigned int
    Public SwatheBlock As UInteger

    '''DWORD->unsigned int
    Public ThisSwathe As UInteger

    '''DWORD->unsigned int
    Public NextSwatheBlock As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public MemoryBlock() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public FirstMemoryBlock() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public MemoryBlocksNeeded() As UInteger

    '''DWORD->unsigned int
    Public PreLoadSwatheBlock As UInteger

    '''DWORD->unsigned int
    Public PrintMode As UInteger

    '''boolean
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)>
    Public PrintOnce As Boolean

    '''DWORD->unsigned int
    Public CycleMode As UInteger

    '''boolean
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)>
    Public ForwardBuffer As Boolean

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public StartDir() As UInteger

    '''DWORD->unsigned int
    Public DirBlock As UInteger

    '''DWORD->unsigned int
    Public SubPixelDivide As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public SaveSubPixelOffset(,) As UInteger

    '''DWORD->unsigned int
    Public SubPixelOffset As UInteger

    '''DWORD->unsigned int
    Public EncoderDivide As UInteger

    '''DWORD->unsigned int
    Public TrailChannels As UInteger

    '''DWORD->unsigned int
    Public LeadChannels As UInteger

    '''DWORD->unsigned int
    Public DataChannels As UInteger

    '''DWORD->unsigned int
    Public HeadChannels As UInteger

    '''boolean[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public BufferReverse() As Boolean

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public NibbleControl() As UInteger

    '''DWORD->unsigned int
    Public NibbleIndex As UInteger

    '''DWORD->unsigned int
    Public LoopCount As UInteger

    '''LPSTR->CHAR*
    <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)>
    Public lpDIBBits As String

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public TotalImageWidth() As UInteger

    '''DWORD->unsigned int
    Public BitDifference As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public NumberSwathes() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public SwatheMemoryCount() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public StoredSwathes() As UInteger

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public PreviousPrintSwathe() As UInteger

    '''boolean[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public AllSwathesFit() As Boolean

    '''boolean
    Public Binary As Boolean

    '''DWORD->unsigned int
    Public GreyLevel As UInteger

    '''boolean[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public FirstSwathe() As Boolean

    '''boolean[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public LastSwathe() As Boolean

    '''boolean[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public LastSwatheInMemory() As Boolean

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public SendID() As UInteger

    '''boolean
    Public BiPrintKeepOdd As Boolean

    '''DWORD->unsigned int
    Public SwatheStartIndex As UInteger

    '''DWORD->unsigned int
    Public SwatheIncrement As UInteger

    '''DWORD->unsigned int
    Public SourceStrokeWidth As UInteger

    '''DWORD->unsigned int
    Public PrintTransportMode As UInteger

    '''boolean
    Public bReverseSwatheOrder As Boolean

    '''boolean
    Public bReverseImageOrder As Boolean

    '''boolean
    Public bPaletteRemap As Boolean

    '''boolean
    Public bBinaryBackgroundInvert As Boolean

    '''DWORD[]
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public SaveProductOffset(,) As UInteger

    '''boolean[]
    Public bSelectHead() As Boolean

    '''DWORD->unsigned int
    Public GuardValue As UInteger

    '''DWORD->unsigned int
    Public SEPDSetup As UInteger

    '''boolean
    Public Enable2Bit As Boolean

    '''BYTE->unsigned char
    Public SysClock As Byte

    '''BYTE->unsigned char
    Public VLDPHCount As Byte

    '''BYTE->unsigned char
    Public Spare As Byte
    '66
End Structure

公共结构PrintDataParameters
''DWORD->无符号整数
作为尤因泰格的公共主管
''DWORD->无符号整数
公共人头类型为UInteger
''德沃德[]
Public HeadIndex()作为UInteger
''DWORD->无符号整数
作为UInteger的公共行数
''DWORD->无符号整数
公共分隔符作为UInteger
''德沃德[]
公共ImageLength()作为UInteger
''德沃德[]
公共ImageSize()作为UInteger
''DWORD->无符号整数
公共产品作为一个整体
''DWORD->无符号整数
公共INTEGAP作为UInteger
''DWORD->无符号整数
作为UInteger的公共FirstSwatheBlock
''DWORD->无符号整数
公共SwatheBlock作为UInteger
''DWORD->无符号整数
公众将此视为一个整体
''DWORD->无符号整数
公共NextSwatheBlock作为UInteger
''德沃德[]
作为UInteger的公共内存块()
''德沃德[]
Public FirstMemoryBlock()作为UInteger
''德沃德[]
公共内存BlocksNeed()作为UInteger
''DWORD->无符号整数
作为UInteger的公共块
''DWORD->无符号整数
作为UInteger的公共打印模式
''布尔
作为布尔值的公共PrintOnce
''DWORD->无符号整数
作为UInteger的公共CycleMode
''布尔
作为布尔值的公共转发缓冲区
''德沃德[]
公共StartDir()作为UInteger
''DWORD->无符号整数
公共数据块作为UInteger
''DWORD->无符号整数
公共子像素划分为UInteger
''德沃德[]
将Subpixeloffset(,)公共存储为UInteger
''DWORD->无符号整数
作为UInteger的公共子像素偏移
''DWORD->无符号整数
公共编码器,如UInteger
''DWORD->无符号整数
作为UInteger的公共跟踪通道
''DWORD->无符号整数
公共领导渠道作为UInteger
''DWORD->无符号整数
作为UInteger的公共数据通道
''DWORD->无符号整数
作为UInteger的公共频道
''布尔[]
Public BufferReverse()作为布尔值
''德沃德[]
作为UInteger的公共NibbleControl()
''DWORD->无符号整数
作为UInteger的公共NibbleIndex
''DWORD->无符号整数
公共循环计数为UInteger
''LPSTR->CHAR*
作为字符串的公共位
''德沃德[]
公共TotalImageWidth()作为UInteger
''DWORD->无符号整数
公共比特差异作为UInteger
''德沃德[]
公用号码wathers()作为UInteger
''德沃德[]
作为UInteger的公共SwatheMemoryCount()
''德沃德[]
公共存储的wathers()作为UInteger
''德沃德[]
作为UInteger的公共上一个printswathe()
''布尔[]
Public allswateshesfit()为布尔值
''布尔
作为布尔值的公共二进制
''DWORD->无符号整数
公共灰度级
''布尔[]
Public FirstSwathe()作为布尔值
''布尔[]
作为布尔值的公共LastSwathe()
''布尔[]
公共内存()为布尔值
''德沃德[]
作为UInteger的公共SendID()
''布尔
公共biprintKeepod作为布尔值
''DWORD->无符号整数
作为UInteger的公共SwatheStartIndex
''DWORD->无符号整数
公共区域作为UInteger的增量
''DWORD->无符号整数
公共源StrokeWidth作为UInteger
''DWORD->无符号整数
作为UInteger的公共交通模式
''布尔
公共bReverseSwatheOrder作为布尔值
''布尔
公共bReverseImageOrder作为布尔值
''布尔
作为布尔值的公共BPaletterMap
''布尔
公共bBinaryBackgroundInvert为布尔值
''德沃德[]
作为UInteger的公共SaveProductOffset(,)
''布尔[]
作为布尔值的公共bSelectHead()
''DWORD->无符号整数
作为一个整体的公共安全价值
''DWORD->无符号整数
公共SEPDSetup为UInteger
''布尔
Public Enable2Bit作为布尔值
''字节->无符号字符
作为字节的公共系统时钟
''字节->无符号字符
公共VLDPH计数为字节
''字节->无符号字符
公共备用字节
'66
端部结构


您在dllimport上使用了Out属性。如果您想查看DLL对您的结构所做的任何更改,请不要这样做

至于你的其他错误,如果我们不知道它们是什么,我们就无法帮助你

。。。他们都是“0”。。。这可能是什么原因

你得到的答案毫无帮助。实际上,您确实需要
属性,由于数组和布尔成员的原因,该结构是不可“blittable”的。一个100美元的单词,这意味着pinvoke封送拆收器不能只传递一个指向托管变量的指针,因为非托管布局与托管布局不同。默认情况下,pinvok