import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.ptr.ShortByReference;



public class Program
{
	public interface TdxHqLibrary extends Library 
	{
		void TdxHq_Disconnect();
		boolean  TdxHq_Connect(String IP, int Port, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetSecurityBars(byte Category, byte Market, String Zqdm, short Start, ShortByReference Count, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetIndexBars(byte Category, byte Market, String Zqdm, short Start, ShortByReference Count, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetMinuteTimeData(byte Market, String Zqdm, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetHistoryMinuteTimeData(byte Market, String Zqdm, int date,byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetTransactionData(byte Market,String Zqdm, short Start, ShortByReference Count, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetHistoryTransactionData(byte Market, String Zqdm, short Start, ShortByReference Count, int date, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetSecurityQuotes(byte[] Market, String[] Zqdm, ShortByReference Count, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetCompanyInfoCategory(byte Market, String Zqdm, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetCompanyInfoContent(byte Market, String Zqdm, String FileName, int Start, int Length, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetXDXRInfo(byte Market, String Zqdm, byte[] Result, byte[] ErrInfo);
		boolean  TdxHq_GetFinanceInfo(byte Market, String Zqdm, byte[] Result, byte[] ErrInfo);
                boolean  TdxHq_GetSecurityCount(byte Market, ShortByReference Result, byte[] ErrInfo);
                boolean  TdxHq_GetSecurityList(byte Market, short Start, ShortByReference  Count, byte[] Result, byte[] ErrInfo);
	}
	
	public static void main(String[] args) 
	{
		try
		{
			//DLL32λ,˱ʹjdk32λ,ܵDLL;
			//TdxHqApi.dllƵjavaĿ¼;
			//java̱ jna.jar,  https://github.com/twall/jna  jna.jar
			//ʲôԱ̣ϸĶVCڵĹDLLĹܺͲ˵ϸĶʱ侫ޣˡ
			TdxHqLibrary TdxHqLibrary1 = (TdxHqLibrary)Native.loadLibrary("TdxHqApi",TdxHqLibrary.class);
			
			
			byte[] Result = new byte[65535];
			byte[] ErrInfo = new byte[256];

			

			boolean boolean1=TdxHqLibrary1.TdxHq_Connect("218.18.103.38", 7709, Result, ErrInfo);
			if (!boolean1)
			{
				System.out.println(Native.toString(ErrInfo, "GBK"));
				return;
			}
			System.out.println(Native.toString(Result, "GBK"));
			
		
			byte[] Market={0,1};
			String[] Zqdm={"000750","600030"};
			ShortByReference Count=new ShortByReference();
			Count.setValue((short)2);
			boolean1 =TdxHqLibrary1.TdxHq_GetSecurityQuotes(Market,  Zqdm,  Count, Result, ErrInfo);
			if (!boolean1)
			{
				System.out.println(Native.toString(ErrInfo, "GBK"));
				return;
			}
			System.out.println(Native.toString(Result, "GBK"));
			
			
			
			ShortByReference Count2=new ShortByReference();
			Count2.setValue((short)20);
			boolean1=TdxHqLibrary1.TdxHq_GetIndexBars((byte)0,(byte)1,"000001",(short) 0, Count2, Result, ErrInfo);
			if (!boolean1)
			{
				System.out.println(Native.toString(ErrInfo, "GBK"));
				return;
			}
			System.out.println(Native.toString(Result, "GBK"));
			
			
			
			ShortByReference Count3=new ShortByReference();
			Count3.setValue((short)80);
			boolean1=  TdxHqLibrary1.TdxHq_GetTransactionData((byte)0, "000001",(short) 0, Count3, Result, ErrInfo);
			if (!boolean1)
			{
				System.out.println(Native.toString(ErrInfo, "GBK"));
				return;
			}
			System.out.println(Native.toString(Result, "GBK"));
			
			
			
			
			boolean1= TdxHqLibrary1.TdxHq_GetCompanyInfoContent((byte)0,"000001", "000001.txt", 0, 10240, Result, ErrInfo);
			if (!boolean1)
			{
				System.out.println(Native.toString(ErrInfo, "GBK"));
				return;
			}
			System.out.println(Native.toString(Result, "GBK"));
			
			
			
			TdxHqLibrary1.TdxHq_Disconnect();
			
			System.out.println("ѶϿ");
		}
		catch(Exception e)
		{
			
		}
	}
}
