2015-10-07 26 views
0

你好我已經從c#創建了一個DLL,它帶有一個返回ArrayList的函數,現在我正試圖在PowerBuilder應用程序中調用它。我怎樣才能從我的PowerBuilder應用程序中的DLL處理返回的ArrayList?還是有其他方法比使用ArrayList?提前致謝。如何從C#處理'ArrayList'到PowerBuilder

這裏是我的C#代碼

using System; 
using System.Collections; 
using System.Linq; 
using System.Text; 
using System.IO.Ports; 
using System.Management; 

namespace GetPorts 
{ 
public class Class1 
{ 
    public ArrayList getPortNames() 
    { 
     ArrayList com_port_name = new ArrayList(); 

     using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort")) 
     { 
      string[] portnames = SerialPort.GetPortNames(); 
      var ports = searcher.Get().Cast<ManagementBaseObject>().ToList(); 
      var tList = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select n + " - " + p["Caption"]).ToList(); 

      foreach (string s in tList) 
      { 
       com_port_name.Add(s); 
      } 
     } 
     return com_port_name; 
    } 
    } 
} 

回答

0

假設這將是一個COM可見的組件有一件事你可以嘗試在PowerBuilder是把返回的字符串數組轉換成一個「任何」變量(或者數組任何變量

像:

any lany[] 
lany = <com_componenet_name>.getportnames() 

當我做這樣的東西的圖片,我設置了一個屬性的類來保存返回值(在你的案件串ARR ay),通過COM公開它,調用方法來設置它的值,然後直接從Powerbuilder引用它。

像:

any lany[] 
string ls[] 
<com_component_name>.getportnames() //set the portnames attribute 
lany = <com_component_name>.portnames() 
ls = la 
// now use the string array in Powerbuilder 
+0

我已經通過COM暴露它,我註冊DLL。現在,我使用「connecttonewobject」來使用我的DLL作爲一個OLE控件,如下所示:'lany = myoleobject.getPortNames()'但是我在這裏得到一個錯誤'Array expected',但是我的函數返回一個ArrayList。 – Dac

+0

非易失性存儲器,我將我的ArrayList轉換爲數組,然後再返回它。多謝老兄! – Dac