我正在研究Amibroker C#插件项目。Amibroker SDK是用C++编写的,但我正在使用一个C#插件,它完全可以像Amibroker C++一样执行C#插件链接
C#插件中的所有内容都正常工作,除了一个用C++编写的函数:
PLUGINAPI struct RecentInfo* GetRecentInfo(LPCTSTR ticker)
{
//Process & return RecentInfo* (RecentInfo is a structure)
}
在C#标准插件中,它被转换为以下方式。
public RecentInfo GetRecentInfo(string ticker)
{
//Process & Return RecentInfo
}
很不幸,Amibroker应用程序在这种错误转换下崩溃。因此,我试图按照自己的方式进行转换,以使Amibroker应用程序正常运行,但多次尝试失败。
以下是我迄今为止尝试过的方法:
尝试1:
unsafe public RecentInfo* GetRecentInfo(string ticker)
{
//Process & Return RecentInfo* (RecentInfo structure is declared as unsafe)
}
影响:
Amibroker 应用程序无法加载。
尝试 2:
public IntPtr GetRecentInfo(string ticker)
{
//Process & Return Pointer using Marshal.StructureToPtr
}
影响:
Amibroker 应用程序无法加载
尝试3:
public void GetRecentInfo(string ticker)
{
//Useless becoz no return type
}
影响:
Amibroker可以正确加载和调用函数,但如何返回结构指针呢?
因此,我正在思考将C++函数精确转换为C#的方法。