STKDRV.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:5k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // STKDRV.cpp: implementation of the CSTKDRV class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Stockdrv.h"
  6. #include "STKDRV.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CSTKDRV::CSTKDRV()
  11. {
  12. m_pfnStock_Init = NULL;
  13. m_pfnStock_Quit = NULL;
  14. m_pfnGetTotalNumber = NULL;
  15. m_pfnGetStockByNoEx = NULL;
  16. m_pfnGetStockByCodeEx = NULL;
  17. m_pfnSetupReceiver = NULL;
  18. m_pfnGetStockDrvInfo = NULL;
  19. m_hSTKDrv = NULL;
  20. // GetAdress();
  21. }
  22. CSTKDRV::~CSTKDRV()
  23. {
  24. }
  25. BOOL CSTKDRV::LoadDriver( LPCTSTR lpszDrvPath )
  26. {
  27. ASSERT( NULL != lpszDrvPath );
  28. CString strLibrary = lpszDrvPath;
  29. if( strLibrary.GetLength() <= 0 )
  30. return FALSE;
  31. m_hSTKDrv = LoadLibrary( strLibrary );
  32. if( !m_hSTKDrv ) 
  33. return FALSE;
  34. m_pfnStock_Init = 
  35.     (int (WINAPI *)(HWND,UINT,int)) GetProcAddress(m_hSTKDrv,"Stock_Init");
  36. m_pfnStock_Quit = 
  37. (int (WINAPI *)(HWND)) GetProcAddress(m_hSTKDrv,"Stock_Quit");
  38. m_pfnGetTotalNumber = 
  39. (int (WINAPI *)())GetProcAddress(m_hSTKDrv,"GetTotalNumber");
  40. m_pfnGetStockByNoEx = 
  41. (int (WINAPI *)(int,RCV_REPORT_STRUCTEx *))GetProcAddress(m_hSTKDrv,"GetStockByNoEx");
  42. m_pfnGetStockByCodeEx = 
  43. (int (WINAPI *)(char *,int,RCV_REPORT_STRUCTEx *))GetProcAddress(m_hSTKDrv,"GetStockByCodeEx");
  44. m_pfnSetupReceiver = 
  45. (int (WINAPI *)(BOOL))GetProcAddress(m_hSTKDrv,"SetupReceiver");
  46. m_pfnGetStockDrvInfo = 
  47. (DWORD (WINAPI *)(int,void * ))GetProcAddress(m_hSTKDrv,"GetStockDrvInfo");
  48. return TRUE;
  49. }
  50. void CSTKDRV::UnloadDriver( )
  51. {
  52. if( m_hSTKDrv )
  53. {
  54. FreeLibrary(m_hSTKDrv);
  55. m_hSTKDrv = NULL;
  56. m_pfnStock_Init = NULL;
  57. m_pfnStock_Quit = NULL;
  58. m_pfnGetTotalNumber = NULL;
  59. m_pfnGetStockByNoEx = NULL;
  60. m_pfnGetStockByCodeEx = NULL;
  61. m_pfnSetupReceiver = NULL;
  62. m_pfnGetStockDrvInfo = NULL;
  63. }
  64. }
  65. int CSTKDRV::Stock_Init(HWND hWnd, UINT uMsg, int nWorkMode)
  66. {
  67. if( !m_pfnStock_Init )
  68. return -1;
  69.  return( (*m_pfnStock_Init)(hWnd,uMsg,nWorkMode));
  70. }
  71. int CSTKDRV::Stock_Quit(HWND hWnd)
  72. {
  73. if( !m_pfnStock_Quit )
  74. return -1;
  75. return( (*m_pfnStock_Quit)(hWnd));
  76. }
  77. int CSTKDRV::GetTotalNumber()
  78. {
  79. if( !m_pfnGetTotalNumber )
  80. return 0;
  81. return( (*m_pfnGetTotalNumber)());
  82. }
  83. int CSTKDRV::GetStockByNoEx(int nNo,RCV_REPORT_STRUCTEx * pBuf)
  84. {
  85. if( !m_pfnGetStockByNoEx )
  86. return 0;
  87. return( (*m_pfnGetStockByNoEx)(nNo,pBuf));
  88. }
  89. int CSTKDRV::GetStockByCodeEx(char * pszStockCode,int nMarket,RCV_REPORT_STRUCTEx * pBuf)
  90. {
  91. if( !m_pfnGetStockByCodeEx )
  92. return 0;
  93. return( (*m_pfnGetStockByCodeEx)(pszStockCode,nMarket,pBuf));
  94. }
  95. int CSTKDRV::SetupReceiver(BOOL bShowWindow)
  96. {
  97. if( !m_pfnSetupReceiver )
  98. return -1;
  99. return( (*m_pfnSetupReceiver)(bShowWindow));
  100. }
  101. DWORD CSTKDRV::GetStockDrvInfo(int nInfo, void *pBuf)
  102. {
  103. if( !m_pfnGetStockDrvInfo ) 
  104. return 0;
  105. return( (*m_pfnGetStockDrvInfo)(nInfo,pBuf));
  106. }
  107. ////////////////////////////////////////////////////////////////////////////////////////
  108. // CNetSTKDRV
  109. CNetSTKDRV::CNetSTKDRV()
  110. {
  111. m_pfnStock_Init_Nodialog= NULL;
  112. m_pfnIsEngineWorking = NULL;
  113. m_pfnSetAutoReport = NULL;
  114. m_pfnRequestStockData = NULL;
  115. }
  116. CNetSTKDRV::~CNetSTKDRV()
  117. {
  118. }
  119. BOOL CNetSTKDRV::LoadDriver( LPCTSTR lpszDrvPath )
  120. {
  121. if( CSTKDRV::LoadDriver( lpszDrvPath ) )
  122. {
  123. m_pfnStock_Init_Nodialog = 
  124. (int (WINAPI *)(HWND,UINT,int,const char*,UINT,const char*,const char*)) GetProcAddress(m_hSTKDrv,"Stock_Init_Nodialog");
  125. m_pfnIsEngineWorking = 
  126. (int (WINAPI *)())GetProcAddress(m_hSTKDrv,"IsEngineWorking");
  127. m_pfnSetAutoReport = 
  128. (int (WINAPI *)(int))GetProcAddress(m_hSTKDrv,"SetAutoReport");
  129. m_pfnRequestStockData = 
  130. (int (WINAPI *)(int, STOCK_STRUCTEx *, int, int, int))GetProcAddress(m_hSTKDrv,"RequestStockData");
  131. return TRUE;
  132. }
  133. return FALSE;
  134. }
  135. void CNetSTKDRV::UnloadDriver( )
  136. {
  137. CSTKDRV::UnloadDriver();
  138. m_pfnStock_Init_Nodialog= NULL;
  139. m_pfnIsEngineWorking = NULL;
  140. m_pfnSetAutoReport = NULL;
  141. m_pfnRequestStockData = NULL;
  142. }
  143. int CNetSTKDRV::Stock_Init_Nodialog(HWND hWnd, UINT uMsg, int nWorkMode,
  144. const char *szAddress,UINT nPort,const char *szUser,const char *szPasswd)
  145. {
  146. if( !m_pfnStock_Init_Nodialog )
  147. return -1;
  148.  return( (*m_pfnStock_Init_Nodialog)(hWnd,uMsg,nWorkMode,szAddress,nPort,szUser,szPasswd));
  149. }
  150. int CNetSTKDRV::IsEngineWorking()
  151. {
  152. if( !m_pfnIsEngineWorking )
  153. return FALSE;
  154. return( (*m_pfnIsEngineWorking)());
  155. }
  156. int CNetSTKDRV::SetAutoReport( int bAutoReport )
  157. {
  158. if( !m_pfnSetAutoReport )
  159. return -1;
  160. return( (*m_pfnSetAutoReport)(bAutoReport));
  161. }
  162. int CNetSTKDRV::RequestStockData( int nDataType, STOCK_STRUCTEx * pStocks, int nSize, int nKType, int nDataCount )
  163. {
  164. if( !m_pfnRequestStockData )
  165. return 0;
  166. return( (*m_pfnRequestStockData)(nDataType,pStocks,nSize,nKType,nDataCount));
  167. }