Пример #1
0
        //获取某个市场或者全部市场的代码表。strMarket取值: "SH"、"SZ"、"CF"、"SHF"、"CZC"、"DCE",全部市场:""
        public TDBErrNo GetCodeTable(string strMarket, out TDBCode[] codeArr)
        {
            TDBErrNo nVerifyRet = SimpleVerifyReqInput(strMarket);

            codeArr = new TDBCode[0];
            if (nVerifyRet != TDBErrNo.TDB_SUCCESS)
            {
                return(nVerifyRet);
            }
            int nArrLen = 128;

            byte[] btMarketArr      = LibWrapHelper.String2AnsiArr(strMarket, nArrLen);
            IntPtr pUnmanagedMarket = Marshal.AllocHGlobal(btMarketArr.Length);

            Marshal.Copy(btMarketArr, 0, pUnmanagedMarket, nArrLen);
            IntPtr ppCodeTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
            IntPtr pCount      = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int32)));

            int    nRet       = LibTDBWrap.TDB_GetCodeTable(m_hTdb, pUnmanagedMarket, ppCodeTable, pCount);
            IntPtr pCodeTable = (IntPtr)Marshal.PtrToStructure(ppCodeTable, typeof(IntPtr));
            int    nCount     = (Int32)Marshal.PtrToStructure(pCount, typeof(Int32));

            if (nRet == 0 && (UInt64)pCodeTable != 0 && nCount > 0)
            {
                codeArr = new TDBCode[nCount];
                int nElemLen = Marshal.SizeOf(typeof(LibTDBWrap.TDBDefine_Code));
                for (int i = 0; i < nCount; i++)
                {
                    LibTDBWrap.TDBDefine_Code apiCode = (LibTDBWrap.TDBDefine_Code)Marshal.PtrToStructure((IntPtr)((UInt64)pCodeTable + (UInt64)(nElemLen * i)), typeof(LibTDBWrap.TDBDefine_Code));
                    codeArr[i] = new TDBCode();
                    codeArr[i].FromAPICode(ref apiCode);
                }
            }
            else
            {
                //如果网络连接断掉,则关闭连接
                if (nRet == (int)TDBErrNo.TDB_NETWORK_ERROR)
                {
                    DisConnect();
                }
            }

            if ((UInt16)pCodeTable != 0)
            {
                LibTDBWrap.TDB_Free(pCodeTable);
            }

            Marshal.FreeHGlobal(pUnmanagedMarket);
            Marshal.FreeHGlobal(ppCodeTable);
            Marshal.FreeHGlobal(pCount);
            return((TDBErrNo)nRet);
        }
Пример #2
0
        //如果查询的代码不存在,连接已经断掉、未连接,则返回null
        public TDBCode GetCodeInfo(string strWindCode, string strMarketKey)
        {
            TDBErrNo nVerifyRet = SimpleVerifyReqInput(strWindCode);

            if (nVerifyRet != TDBErrNo.TDB_SUCCESS)
            {
                return(null);
            }
            int    nMaxWindCodeLen = 64;
            int    nMaxmarketLen   = 48;
            IntPtr pszWindCode     = Marshal.AllocHGlobal(nMaxWindCodeLen);

            byte[] btWindCode = LibWrapHelper.String2AnsiArr(strWindCode, nMaxWindCodeLen);
            btWindCode[btWindCode.Length - 1] = 0;
            Marshal.Copy(btWindCode, 0, pszWindCode, btWindCode.Length);

            IntPtr pszMarket = Marshal.AllocHGlobal(nMaxmarketLen);

            byte[] btMarket = LibWrapHelper.String2AnsiArr(strMarketKey, nMaxmarketLen);
            btMarket[btMarket.Length - 1] = 0;
            Marshal.Copy(btMarket, 0, pszMarket, btMarket.Length);

            IntPtr pCode = LibTDBWrap.TDB_GetCodeInfo(m_hTdb, pszWindCode, pszMarket);

            Marshal.FreeHGlobal(pszWindCode);
            Marshal.FreeHGlobal(pszMarket);
            if ((UInt64)pCode != 0)
            {
                LibTDBWrap.TDBDefine_Code apiCode = (LibTDBWrap.TDBDefine_Code)Marshal.PtrToStructure(pCode, typeof(LibTDBWrap.TDBDefine_Code));
                TDBCode tdbCode = new TDBCode();
                tdbCode.FromAPICode(ref apiCode);
                return(tdbCode);
            }
            else
            {
                return(null);
            }
        }