簡體   English   中英

如何在c#函數中轉換C ++函數

[英]How do i convert a C++ function in c# function

我正在研究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 App工作,但多次失敗這是我到目前為止所嘗試的:

嘗試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 ++函數的確切轉換

如果完全用c#寫的那么,這很好,認為實現中存在問題而不是調用

public RecentInfo GetRecentInfo(string ticker)
{
      RecentInfo rc;
    //Process & Return RecentInfo
      return rc;
}

或者這個,(你也可以使用ref)

public void GetRecentInfo(string ticker,out RecentInfo rc )
{
rc=new RecentInfo();
....process

 return ;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM