public static void OnRspQryInstrument(IntPtr pContex, bool bSuccess, IntPtr pInstruments, int nCount, IntPtr pszErrorMsg) { //Console.WriteLine("OnRspQryInstrument: " + Marshal.PtrToStringAnsi(pszErrorMsg)); Sys_log = Sys_log + "\n" + DateTime.Now.ToString() + ": 正在查询股票:" + Marshal.PtrToStringAnsi(pszErrorMsg); tagSTRUCT_INSTRUMENT[] Instruments = new tagSTRUCT_INSTRUMENT[nCount]; for (int i = 0; i < nCount; i++) { IntPtr pinstruments = (IntPtr)((UInt32)pInstruments + i * Marshal.SizeOf(typeof(tagSTRUCT_INSTRUMENT))); Instruments[i] = (tagSTRUCT_INSTRUMENT)Marshal.PtrToStructure(pinstruments, typeof(tagSTRUCT_INSTRUMENT)); //Console.WriteLine((i + 1).ToString() + "\t" + Instruments[i].ExchangeID + "." + Instruments[i].InstrumentID + "\t" + Instruments[i].InstrumentName); } }
public static void OnInstrument(IntPtr AContex, IntPtr pRtn, int nCount) { tagSTRUCT_INSTRUMENT[] Data = new tagSTRUCT_INSTRUMENT[nCount]; if (pRtn != IntPtr.Zero && nCount > 0) { string path = @"D:\\instrument.txt"; using (StreamWriter sw = File.CreateText(path)) { for (int i = 0; i < nCount; i++) { IntPtr pdata = (IntPtr)((UInt32)pRtn + i * Marshal.SizeOf(typeof(tagSTRUCT_INSTRUMENT))); Data[i] = (tagSTRUCT_INSTRUMENT)Marshal.PtrToStructure(pRtn, typeof(tagSTRUCT_INSTRUMENT)); sw.WriteLine(Data[i].ExchangeID + "." + Data[i].InstrumentID + " " + Data[i].InstrumentName + " " + Data[i].MinBuyVolume + " " + Data[i].PriceTick); } } } }