/////////////////////////////////////////////////////////
/////   NxCoreLoadLib.h                             /////
/////   Load/Unload NxCore DLL                      /////
/////   Define the NxCore DLL Functions             /////
/////////////////////////////////////////////////////////
/////   To Read as Writtem:                         /////
/////   Tab Size: 4 Indent Size: 4                  /////
/////////////////////////////////////////////////////////
/////	Copyright (c) 2009. Eric Scott Hunsader		/////
/////////////////////////////////////////////////////////

#ifndef NXCORE_API_LOADLIB_H
#define NXCORE_API_LOADLIB_H

#include "windows.h"
#include "NxCoreAPI.h"

HMODULE NxLib;

NxCoreProcessTape         pfNxCoreProcessTape;
NxCoreAPIVersion		  pfNxCoreAPIVersion;
NxCoreListTapes			  pfNxCoreListTapes;
NxCoreListAPIDLLs		  pfNxCoreListAPIDLLs;
NxCoreSpinSymbols		  pfNxCoreSpinSymbols;
NxCoreSaveState			  pfNxCoreSaveState;
NxCoreGetStateData		  pfNxCoreGetStateData;
NxCoreStateGetExgQuotes	  pfNxCoreStateGetExgQuotes;
NxCoreStateGetMMQuotes	  pfNxCoreStateGetMMQuotes;
NxCoreStateGetLastTrade	  pfNxCoreStateGetLastTrade;
NxCorePriceConvert		  pfNxCorePriceConvert;
NxCorePriceFormat		  pfNxCorePriceFormat;
NxCorePriceToDouble		  pfNxCorePriceToDouble;
NxCoreDateFromNDays		  pfNxCoreDateFromNDays;
NxCoreDateFromYMD		  pfNxCoreDateFromYMD;
NxCoreGetDefinedString	  pfNxCoreGetDefinedString;
NxCoreGetTapeName		  pfNxCoreGetTapeName;
NxCoreSignalWaitEvent	  pfNxCoreSignalWaitEvent;
NxCoreSetCallback	      pfNxCoreSetCallback;

//------------------------------------------------------------
unsigned char LoadNxCore(char *FileName)
{
  NxLib= ::LoadLibrary(FileName);
  
  if( NxLib ) {		
      pfNxCoreProcessTape      = (NxCoreProcessTape)       ::GetProcAddress(NxLib,"sNxCoreProcessTape");
	  pfNxCoreAPIVersion       = (NxCoreAPIVersion)        ::GetProcAddress(NxLib,"sNxCoreAPIVersion");    
      pfNxCoreListTapes        = (NxCoreListTapes)         ::GetProcAddress(NxLib,"sNxCoreListTapes");
      pfNxCoreListAPIDLLs      = (NxCoreListAPIDLLs)       ::GetProcAddress(NxLib,"sNxCoreListAPIDLLs");
      pfNxCoreSpinSymbols      = (NxCoreSpinSymbols)       ::GetProcAddress(NxLib,"sNxCoreSpinSymbols");
      pfNxCoreSaveState        = (NxCoreSaveState)         ::GetProcAddress(NxLib,"sNxCoreSaveState");
      pfNxCoreGetStateData     = (NxCoreGetStateData)      ::GetProcAddress(NxLib,"sNxCoreGetStateData");
      pfNxCoreStateGetExgQuotes= (NxCoreStateGetExgQuotes) ::GetProcAddress(NxLib,"sNxCoreStateGetExgQuotes");
      pfNxCoreStateGetMMQuotes = (NxCoreStateGetMMQuotes)  ::GetProcAddress(NxLib,"sNxCoreStateGetMMQuotes");
      pfNxCoreStateGetLastTrade= (NxCoreStateGetLastTrade) ::GetProcAddress(NxLib,"sNxCoreStateGetLastTrade");
      pfNxCorePriceConvert     = (NxCorePriceConvert)      ::GetProcAddress(NxLib,"sNxCorePriceConvert");
      pfNxCorePriceFormat      = (NxCorePriceFormat)       ::GetProcAddress(NxLib,"sNxCorePriceFormat");
      pfNxCorePriceToDouble    = (NxCorePriceToDouble)     ::GetProcAddress(NxLib,"sNxCorePriceToDouble");    
      pfNxCoreDateFromNDays    = (NxCoreDateFromNDays)     ::GetProcAddress(NxLib,"sNxCoreDateFromNDays");
      pfNxCoreDateFromYMD      = (NxCoreDateFromYMD)       ::GetProcAddress(NxLib,"sNxCoreDateFromYMD");
      pfNxCoreGetDefinedString = (NxCoreGetDefinedString)  ::GetProcAddress(NxLib,"sNxCoreGetDefinedString");
      pfNxCoreGetTapeName      = (NxCoreGetTapeName)       ::GetProcAddress(NxLib,"sNxCoreGetTapeName");
      pfNxCoreSignalWaitEvent  = (NxCoreSignalWaitEvent)   ::GetProcAddress(NxLib,"sNxCoreSignalWaitEvent");
	  pfNxCoreSetCallback      = (NxCoreSetCallback)       ::GetProcAddress(NxLib,"sNxCoreSetCallback");

      return 1;
  }  
  return 0;
}

//------------------------------------------------------------
void UnloadNxCore(void)
{
	if (NxLib) ::FreeLibrary(NxLib);
}

#endif // NXCORE_API_LOADLIB_H

