Hello I have created a DLL from c# with a function that returns an ArrayList, and now I am trying to call it in my PowerBuilder app. How can I handle the returned ArrayList from the DLL in my PowerBuilder App? Or are there other ways than using an ArrayList? Thanks in advance.
Here is my c# code
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;
}
}
}
Assuming this will be a COM visible component one thing you could try in Powerbuilder is to bring the returned string array into an 'any' variable (or perhaps an array of any variables
Like:
any lany[]
lany = <com_componenet_name>.getportnames()
When I've done stuff like this for images, I set up an attribute on the class to hold the return value (in your case a string array), exposed it via COM, called the method to set its value, then referenced it directly from Powerbuilder.
Like:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.