如何将列表从C ++ Dll传递给C# [英] How to Pass a List from a C++ Dll to C#
问题描述
我正在尝试编写一个函数,它将从C ++ DLl返回到C#的记录列表,其中包含C ++中的记录列表。最终目标是导出函数并在C#中调用函数并获取记录。我知道如何在C ++中导出
函数。但是,你能否指出在c ++中设置函数的正确方向。
pianoboyCoder
I am trying to write a function that will return a List of records from a C++ DLl to C#, which contain of list of records in C++. The end goal is to export the function and call the function in C# and get the records. I know how to export
the function in C++. However, can you point in the right direction in setting up the function in c++.
pianoboyCoder
推荐答案
如果您打算从C#调用非托管C ++代码,我建议您先阅读
使用平台调用封送数据。
这将帮助您了解如何在非托管代码和托管代码之间传递数据,并帮助您确定如何定义"记录列表"。并实现您的非托管C ++函数。 在确定了数据是如何在非托管C ++和C#中表示
之后,我们可以帮助您解决如何实现 的详细信息。使用P / Invoke的C#代码。
This will help you to understand how data is passed between unmanaged and managed code and will help you determine how you should define your "List of records" and implement your unmanaged C++ function. After you have determined how
the data is to be represented in both unmanaged C++ and also in C# then we can help you address the specifics of how to implement the C# code that uses P/Invoke.
编辑:
除了使用P / Invoke之外,还可以使用在非托管C ++和C#之间传递数据的其他常用方法COM或使用C ++ / CLI编写的DLL,充当非托管C ++和C#之间的中介。
Besides using P/Invoke the other common methods of passing data between unmanaged C++ and C# are to use COM or a DLL written using C++/CLI that acts as an intermediary between unmanaged C++ and C#.
这篇关于如何将列表从C ++ Dll传递给C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!