C# 如何从c到PowerBuilder处理“ArrayList”
您好,我已经从c创建了一个DLL,其中包含一个返回ArrayList的函数,现在我正试图在我的PowerBuilder应用程序中调用它。如何在PowerBuilder应用程序中处理从DLL返回的ArrayList?或者除了使用ArrayList还有其他方法吗?提前谢谢 这是我的c代码C# 如何从c到PowerBuilder处理“ArrayList”,c#,dll,arraylist,powerbuilder,C#,Dll,Arraylist,Powerbuilder,您好,我已经从c创建了一个DLL,其中包含一个返回ArrayList的函数,现在我正试图在我的PowerBuilder应用程序中调用它。如何在PowerBuilder应用程序中处理从DLL返回的ArrayList?或者除了使用ArrayList还有其他方法吗?提前谢谢 这是我的c代码 using System; using System.Collections; using System.Linq; using System.Text; using System.IO.Ports; using
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;
}
}
}
假设这将是一个COM可见组件,您可以在Powerbuilder中尝试的一件事是将返回的字符串数组放入一个“any”变量或任何变量的数组中 比如: 当我为图像做了类似的事情时,我在类上设置了一个属性来保存返回值,在您的例子中是一个字符串数组,通过COM公开它,调用方法来设置它的值,然后直接从Powerbuilder引用它 比如:
我已经通过COM公开了它,并注册了我的DLL。现在,我使用ConnectToneObject将我的DLL用作OLE控件,例如:“lany=myoleobject.getPortNames”,但我在这里得到一个错误,它是“预期的数组”,但我的函数返回一个ArrayList.NVM,我在返回ArrayList之前将它转换为数组。非常感谢你,伙计!
any lany[]
lany = <com_componenet_name>.getportnames()
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