Reputation: 5620
I am working on Amibroker C# plugin project. Amibroker SDK is written in C++ but, I am using a C# plugin which does exactly what Amibroker C++ does C# Plugin link
Everything in C# plugin works just fine except one function which is written in c++ this way:
PLUGINAPI struct RecentInfo* GetRecentInfo(LPCTSTR ticker)
{
//Process & return RecentInfo* (RecentInfo is a structure)
}
In C# standard plugin it has been converted this way
public RecentInfo GetRecentInfo(string ticker)
{
//Process & Return RecentInfo
}
Unfortunately, Amibroker application crashes with this wrong conversion. So I did try to convert it my way to get Amibroker App working, but failed multiple times This is what i have tried so far:
unsafe public RecentInfo* GetRecentInfo(string ticker)
{
//Process & Return RecentInfo* (RecentInfo structure is declared as unsafe)
}
Amibroker app does not load
public IntPtr GetRecentInfo(string ticker)
{
//Process & Return Pointer using Marshal.StructureToPtr
}
Amibroker app does not load
public void GetRecentInfo(string ticker)
{
//Useless becoz no return type
}
Amibroker loads & does call function correctly but how do return a structure pointer
So, I am scratching my head to find out the exact conversion of C++ function in C#
Upvotes: 3
Views: 340
Reputation: 3670
If it is fully written in c# then , this is pretty well ,think there is problem in implementation not in calling
public RecentInfo GetRecentInfo(string ticker)
{
RecentInfo rc;
//Process & Return RecentInfo
return rc;
}
or this , (you can use ref too)
public void GetRecentInfo(string ticker,out RecentInfo rc )
{
rc=new RecentInfo();
....process
return ;
}
Upvotes: 2