如果我對此有正確的解決方法,不知道該怎麼辦?以下結構的內容在其他地方定義。當我運行代碼時,它只是輸出一個4個零的列表。任何幫助將不勝感激.....如何在c#窗體窗體應用程序中的列表框中顯示結構的內容
public class NativeMethods
{
public struct FT_DEVICE_LIST_INFO_NODE
{
public uint ID;
public uint LocId;
public string SerialNumber;
public string Description;
}
[DllImportAttribute(@"C:\Users\Brendan\Documents\libMPSSE.dll", EntryPoint = "SPI_GetNumChannels")]
public static extern uint SPI_GetChannelInfo(uint index, ref FT_DEVICE_LIST_INFO_NODE chanInfo);
}
public partial class Form1 : Form
{
List<uint> items = new List<uint>();
public Form1()
{
InitializeComponent();
NativeMethods.FT_DEVICE_LIST_INFO_NODE devlist = new NativeMethods.FT_DEVICE_LIST_INFO_NODE();
for(uint x=0;x<4;x++)
{
index = 0;
items.Add(NativeMethods.SPI_GetChannelInfo(index, ref devlist));
}
listBox.DataSource = items;
}
}
你的外部函數SPI_GetChannelInfo是否具有DllImport屬性?你有沒有嘗試調試外部代碼(如果可以的話)? – 2014-11-24 13:41:23
是的,它導入一個C DLL,我知道它是作爲 我已經輸出其內容到其他文本框。我似乎無法將所有參數輸出到列表框中,也許這是因爲它們是不同類型的參數uint和string? – john 2014-11-24 13:49:12
我離開了DllImport屬性,使其更簡單 – john 2014-11-24 13:55:01