简体   繁体   English

来自C ++的C#包装器类和dllimport

[英]C# wrapper class and dllimport from c++

The idea is to make C# wrapper class. 这个想法是使C#包装类。 I know the structure but I don't know how to use pointers same way or that way it works similarly since my skills in C# doesn't occur. 我知道结构,但是我不知道如何以相同的方式使用指针或以类似的方式使用指针,因为我的C#技能没有出现。 (read translation to C# from C++). (从C ++阅读到C#的翻译)。 If I'm right the memory usage in C# is way different. 如果我是对的,C#中的内存使用情况将有所不同。

The structure is this. 结构是这个。

public class Unknown
{
    [DllImport("UnknownSDK.dll")]
    //functions to be translated
}

Functions to be translated: 要翻译的功能:

bool setA(int id, int i);
bool set1(int max, level *many);
bool getA(frame * const * const fame);
void give(frame * const * const fame);

Thanks in advance. 提前致谢。

Here is the structure of level: 这是级别的结构:

  typedef struct level {

    int A;
    int B;
    int fade;
} level;

Structure of frame: 框架结构:

  typedef struct frame {

    DWORD header;
    DWORD padding;
    BYTE bpadding[2];
    int asd;
    group_t group[1];
} frame;

I hope this clarifies it a bit. 我希望这可以澄清一下。 And the main problem I would say is these pointers and * const * const structure in C#. 我要说的主要问题是C#中的这些指针和* const * const结构。 I will also tell you later what my studies taught me but it is still learning so I don't have any test code to show you since I haven't got the whole picture of it yet. 稍后,我还将告诉您我的学习中学到了什么,但它仍在学习中,因此我没有任何测试代码可以显示给您,因为我还没有了解它的全部情况。

this is the way to import method : 这是导入方法的方法:

[DllImport("UnKnowSDK.dll")]
private static extern bool setA(int id, int i);

And you can call simply the method like this: 您可以简单地调用如下方法:

bool res = setA(1,2);

To pass as a parameter a structure is necessary to know its exact structure and replicate it in c #. 要将结构作为参数传递,必须知道其确切结构并将其复制到c#中。 To manipolate the data you can use: 要处理数据,您可以使用:

    Frame fr = new FrameStruct();
fr= (ExchangeStruct)Marshal.PtrToStructure(frame, typeof(FrameStruct));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM