0
我開始將C++/CLI與IronPython結合起來:) 我遇到了Python代碼中託管結構的問題。 我的結構看起來像這樣將C++/CLI結構傳遞給IronPython PythonFunction
[System::Runtime::InteropServices::StructLayout(
System::Runtime::InteropServices::LayoutKind::Sequential)]
public value struct VersionInfo
{
[System::Runtime::InteropServices::MarshalAsAttribute(
System::Runtime::InteropServices::UnmanagedType::U4)]
DWORD Major;
};
傳遞這個結構,Python是如下
VersionInfo^ vi = gcnew VersionInfo();
vi->Major = 12345;
IronPython::Runtime::PythonFunction^ function =
(IronPython::Runtime::PythonFunction^)
m_PluginScope->GetVariable("GetGlobalInfo");
array<VersionInfo^>^ args = gcnew array<VersionInfo^>(1)
{
vi
};
auto result = m_Engine->Operations->Invoke(function, args);
最後,Python代碼:
def GetGlobalInfo(info):
info.Major = 55
return info.Major
在結果的返回值是不是 55如預期的那樣,但是12345. Can any正文請幫我弄清楚,爲什麼Python的代碼沒有改變這個值? 感謝
謝謝。我在結構定義中用_ref_取代_value_,現在它正在工作。 –