gpt4 book ai didi

c# - 将复杂结构从 C++ 编码到 C#

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:49:34 25 4
gpt4 key购买 nike

几天来,我一直在尝试将一个复杂的结构从 C++ 编码到 C#,基本上我已经设法完成了我想要完成的大部分工作,但现在我一直在尝试编码我认为是的东西一个列表。

在示例中,我将包括我所做的工作以及我遇到的问题。

public: void __thiscall TransactionModule_t::GetTransaction(class Identity_t const &)const 

符合以下条件:

// public: void __thiscall TransactionModule_t::GetTransaction(class Identity_t const &)const     
[DllImport("Transaction.dll", EntryPoint = "?GetTransaction@TransactionModule_t@@Identity_t@@@Z", CallingConvention = CallingConvention.ThisCall)]
public static extern void GetTransaction(IntPtr iPtr,[Out, MarshalAs(UnmanagedType.LPStruct)] Identity transaction);


[StructLayout(LayoutKind.Sequential)]
[Serializable]
public class Identity
{
public uint Id;
public uint Type;

public Identity(uint id = 0, uint type = 0)
{
this.Id = id;
this.Type = type;
}
}

这工作得很好。

但是我想调用一个方法来给我列表。

public: void __thiscall TransactionModule_t::GetTransactions(class std::vector<class Identity_t,class std::allocator<class Identity_t> > &)const 

我卡住的地方:

// public: void __thiscall TransactionModule_t::GetTransactions(class std::vector<class Identity_t,class std::allocator<class Identity_t> > &)const 
[DllImport("Transaction.dll", EntryPoint = "long mangled entry point", CallingConvention = CallingConvention.ThisCall)]
public static extern void GetTransactions(IntPtr iPtr,[Out] Transactions transactions);

我尝试创建一个介于两者之间的类。

[StructLayout(LayoutKind.Sequential)]
[Serializable]
public class Transactions
{
public Identity Identity;
public Identity[] List;
}

甚至可以调用此方法吗,我在这里遗漏了什么吗?

最佳答案

Is it even possible to call this method?

不,不是。您不能从 C# 代码提供 std::vector

实际上,您将需要一个 C++/CLI 包装器。

关于c# - 将复杂结构从 C++ 编码到 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31600144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com