Marshaling c structures in c#

前端 未结 2 1953
暖寄归人
暖寄归人 2020-12-11 12:13

i have one \'C\' \'DLL\' which can take structures as input, i have to call that dll from my c# program

fallowing are the sample structures i have in c, i have to m

相关标签:
2条回答
  • 2020-12-11 12:36

    It's difficult to say for certain, given that you don't know if it's working or not! Regardless, it looks correct to me.

    My recommendation would be to simply test out that structure you've shown here, make sure that it seems to be operating as you'd expect. Then begin to create the other 100 or so structures.

    If it helps, take a look at Marshal C++ struct array into C# and the links therein.

    0 讨论(0)
  • 2020-12-11 12:52

    (Scratch my original answer)

    You need to have this at the top of each struct:

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    

    Note the CharSet named parameter. That's important, or you'll end up with wchar_t arrays instead of char arrays.

    0 讨论(0)
提交回复
热议问题