小编Mes*_*ias的帖子

在VB.NET中修改C结构

我正试图在我的VB.NET应用程序中使用C编码的其他人的DLL.我的VB.NET应用程序发送一些指向DLL和DLL的回调指针,然后回调我的VB.NET应用程序内的函数.

DLL在VB.NET中调用一个函数并传递一个C结构的指针.我的VB.NET应用程序必须修改struct值,因此DLL可以使用新的struct值.我不能修改DLL的代码,因为它是别人的DLL.

typedef struct {
  uint8_t index;
  uint8_t value;
  uint8_t leds[4];
  struct {
    int8_t x;
    int8_t y;
    int8_t z;
  } input[10];
} REPORT;
Run Code Online (Sandbox Code Playgroud)

我的VB.NET结构定义是

<StructLayout(LayoutKind.Sequential)> _
Public Structure INPUTS
    Public x As SByte
    Public y As SByte
    Public z As SByte
End Structure

<StructLayout(LayoutKind.Sequential)> _
Public Structure REPORT
    Public index As Byte
    Public value As Byte

    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)>
    Public leds() As Byte


    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=10)>
    Public input() As INPUTS

    Sub New(numleds As Integer, numinputs As Integer)
        ReDim Me.leds(numleds)
        ReDim Me.input(numinputs)
    End …
Run Code Online (Sandbox Code Playgroud)

c vb.net dll interopservices

16
推荐指数
0
解决办法
931
查看次数

标签 统计

c ×1

dll ×1

interopservices ×1

vb.net ×1