How to Pass a List from a C++ Dll to C#
Question
Tuesday, October 23, 2018 12:34 PM
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
All replies (2)
Tuesday, October 23, 2018 1:12 PM
If it is your intent to call unmanaged C++ code from C# I suggest you start by reading Marshaling Data with Platform Invoke.
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.
Edit:
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#.
Wednesday, October 24, 2018 4:58 PM
Thanks RLWA32. I will create a minimum project again sometime today and upload.
pianoboyCoder