#pragma once

class   CEZGemPlusCtrl;
typedef CEZGemPlusCtrl*	EZGEMCLASS;

typedef void(*pNativeCallBackEvent)(void*, short, long);	// Handle, EventID, Param
typedef void(*pNativeCallBackMsg)(void*, long);			// Handle, SECS MsgId

enum 
{
	TRNASFERSTATE_NOSTATE = 0,
	TRANSFERSTATE_OUTOFSERVICE = 1,  
	TRANSFERSTATE_INSERVICE = 2,
	TRANSFERSTATE_READYTOLOAD = 3, 
	TRANSFERSTATE_READYTOUNLOAD = 4, 
	TRANSFERSTATE_TRANSFERBLOCKED = 5,

	DOORSTATE_CLOSED = 0,
	DOORSTATE_OPENED = 1,

	ACCESSMODE_MANUAL= 0,
	ACCESSMODE_AUTO	 = 1,

	CARRIERACCESS_NOTACCESSED = 0,
	CARRIERACCESS_INACCESS = 1,
	CARRIERACCESS_COMPLETED = 2,
	CARRIERACCESS_STOPPED = 3,

	CARRIERIDREAD_OK	=	0,
	CARRIERIDREAD_FAIL	=	1,

	CARRIERIDSTATE_NOTREAD = 0,
	CARRIERIDSTATE_WAITFORHOST = 1,
	CARRIERIDSTATE_VERIFYOK = 2,
	CARRIERIDSTATE_VERIFYFAIL = 3,

	SLOTMAPREAD_OK	=	0,
	SLOTMAPREAD_FAIL	=	1,

	SLOTMAPSTATE_NOTREAD = 0,
	SLOTMAPSTATE_WAITFORHOST = 1,
	SLOTMAPSTATE_VERIFYOK = 2,
	SLOTMAPSTATE_VERIFYFAIL = 3,

	SLOTMAP_MAXSLOT = 25,
};
enum
{
	// Error Codes
	RESULT_OK = 0,
	LICENSE_PROBLEM = -1,

	CONFIG_FILE_NOTFOUND = -101,
	FILE_NOT_FOUND = -102,
	FILE_IO_FAILURE = -103,
	FILE_CREATION_ERROR = -104,

	ID_NOT_EXIST = -200,
	NO_ITEM = -201,
	TYPE_MISMATCH = -202,
	SIZE_MISMATCH = -203,
	ITEM_I1_OVERFLOW = -204,
	ITEM_I2_OVERFLOW = -205,
	ITEM_I4_OVERFLOW = -206,
	ITEM_U1_OVERFLOW = -207,
	ITEM_U2_OVERFLOW = -208,
	ITEM_U4_OVERFLOW = -209,
	INVALID_MSGID = -210,
	INVALID_STREAM = -211,
	INVALID_FUNCTION = -212,
	DUPLICATE_SYSTEMBYTE = -213,
	UNDEFINED_STRUCTURE = -214,
	OUT_OF_RANGE = -215,

	NOT_CONNECTED = -301,
	LOW_LEVEL_ERROR = -302,
	NOT_SUPPORTED = -303,
	ALREADY_CONNECTED = -304,
	ALREADY_STARTED = -305,
	THREAD_NULL = -306,
	CREATE_EVENT_FAIL = -307,
	SERIAL_OPEN_FAIL = -308,
	SERIAL_SETUP_FAIL = -309,
	TIMER_CREATE_FAIL = -310,
	NOT_STARTED_YET = -311,
	ALREADY_DEFINED = -312,
	NOT_ESTABLISHED = -313,
	NOT_ONLINE_STATE = -314,
	ITEMS_NOT_READY = -315,

	SOCKET_INUSE = -501,
	SOCKET_STARTERROR = -502,
	SOCKET_INVALID = -503,
	SOCKET_WINDOWERROR = -504,
	SOCKET_LOCALNAME = -505,
	SOCKET_CONNECTERROR = -506,
	SOCKET_SETEVENT = -507,
	SOCKET_RESOLVE = -508,

	ERROR_GEM300_INVALID_PORTID = -901,
	ERROR_GEM300_INVALID_STATE = -902,
	ERROR_GEM300_INVALID_MODE = -903,
	ERROR_GEM300_INVALID_DATA = -904,
	ERROR_GEM300_NO_DATA = -905,
	ERROR_GEM300_ALREADY_EXIST = -906,
	ERROR_GEM300_INVALID_CARRIER = -907,
	ERROR_GEM300_INVALID_SLOT = -908,
	ERROR_GEM300_INVALID_RECIPE = -909,
	ERROR_GEM300_INVALID_PRJOB = -910,
	ERROR_GEM300_INVALID_CJOB = -911,
	ERROR_GEM300_INVALID_LOCATION = -912,
	ERROR_GEM300_INVALID_OBJTYPE = -913,
	ERROR_GEM300_INVALID_OBJID = -914,
	ERROR_GEM300_INVALID_ATTR = -915,

	// Event Codes
	DLL_EVENT_CONNECTED = 1,
	DLL_EVENT_DISCONNECTED = 2,
	DLL_EVENT_MSGRECEIVED = 3,
	DLL_EVENT_OTHEREVENT = 9,

	EVENT_KEY_EVALUATION_MODE_START = 10,
	EVENT_KEY_RUNTIME_MODE_START = 11,
	EVENT_LINKTEST_REQUEST_IN = 101,
	EVENT_LINKTEST_REQUEST_OUT = 102,
	EVENT_LINKTEST_RESPONSE_OUT = 104,
	EVENT_TRANSACTION_TIMEOUT = 202,
	EVENT_UNRECOGNIZED_DEVICEID = 203,
	EVENT_UNRECOGNIZED_STREAM = 204,
	EVENT_LINKTEST_RESPONSE_IN = 103,
	EVENT_UNRECOGNIZED_FUNCTION = 205,
	EVENT_INVALID_DATA = 206,
	EVENT_DISCARD_MSG = 207,
	EVENT_ABORTMSG_IN = 208,

	EVENT_TIMEOUT_T1 = 301,
	EVENT_TIMEOUT_T2 = 302,
	EVENT_TIMEOUT_T3 = 303,
	EVENT_TIMEOUT_T4 = 304,
	EVENT_TIMEOUT_T5 = 305,
	EVENT_TIMEOUT_T6 = 306,
	EVENT_TIMEOUT_T7 = 307,
	EVENT_TIMEOUT_T8 = 308,
	EVENT_RETRY_LIMIT = 309,
	EVENT_MSG_IN = 401,
	EVENT_MSG_OUT = 402,
	EVENT_ENABLED = 501,
	EVENT_DATAID_CHANGED = 511,

	EVENT_GEMDLL_CONTROL_HOSTOFFLINE = 1001,
	EVENT_GEMDLL_CONTROL_ONLINE_LOCAL = 1002,
	EVENT_GEMDLL_CONTROL_ONLINE_REMOTE = 1003,
	EVENT_GEMDLL_COMM_ESTABLISHED = 1010,
	EVENT_GEMDLL_HOST_SENT_NEWECV = 1015,
	EVENT_GEMDLL_TRACE_TIMESET = 1020,
	EVENT_GEMDLL_HOST_COMMAND = 1030,
	EVENT_GEMDLL_SPOOL_UPDATED = 1040,
	EVENT_GEMDLL_SPOOL_FULL = 1041,
	EVENT_GEMDLL_TERMMSG = 1050,
	EVENT_GEMDLL_TRANSACTION = 1060,
	EVENT_GEMDLL_IN_DEADBAND = 1070,

	///// GEM300 EVENT //////
	EVENT_GEMDLL_CMS_TRANSFER_STATE_CHANGE = 1301,
	EVENT_GEMDLL_CMS_RESERVATION_STATE_CHANGE = 1311,
	EVENT_GEMDLL_CMS_CARRIERACCESS_STATE_CHANGE = 1321,
	EVENT_GEMDLL_CMS_ASSOCIATION_STATE_CHANGE = 1331,

	EVENT_GEMDLL_CMS_CARRIERID_STATE_CHANGE = 1401,
	EVENT_GEMDLL_CMS_CARRIERID_VERIFY_OK = 1411,
	EVENT_GEMDLL_CMS_CARRIERID_VERIFY_FAILED = 1412,
	EVENT_GEMDLL_CMS_CARRIER_DELETED = 1421,
	EVENT_GEMDLL_CMS_CARRIER_RECREATED = 1422,

	EVENT_GEMDLL_CMS_SLOTMAP_STATE_CHANGE = 1501,
	EVENT_GEMDLL_CMS_SLOTMAP_VERIFY_OK = 1511,
	EVENT_GEMDLL_CMS_SLOTMAP_VERIFY_FAILED = 1512,

	EVENT_GEMDLL_CMS_HOST_PROCEED_WITH_CARRIER = 1601,	//	<<--- HOST : S3F17, ProceedWithCarrier
	EVENT_GEMDLL_CMS_HOST_CANCEL_CARRIER = 1602,	//	<<--- HOST : S3F17, CancelCarrier
	EVENT_GEMDLL_CMS_HOST_CANCEL_CARRIER_AT_PORT = 1603,	//	<<--- HOST : S3F17, CancelCarrierAtPort
	EVENT_GEMDLL_CMS_HOST_BIND = 1604, //  <<--- HOST : S3F17, Bind
	EVENT_GEMDLL_CMS_HOST_CANCELBIND = 1605, //  <<--- HOST : S3F17, CancelBind
	EVENT_GEMDLL_CMS_HOST_RESERVEATPORT = 1606, //  <<--- HOST : S3F17, ReserveAtPort
	EVENT_GEMDLL_CMS_HOST_CANCEL_RESERVEATPORT = 1607,	//  <<--- HOST : S3F17, CancelReservationAtPort
	EVENT_GEMDLL_CMS_HOST_CANCEL_ALLCARRIEROUT = 1608,	//  <<--- HOST : S3F17, CancelAllCarrierOut
	EVENT_GEMDLL_CMS_HOST_CANCEL_CARRIER_NOTIFICATION = 1609, //  <<--- HOST : S3F17, CancelCarrierNotification
	EVENT_GEMDLL_CMS_HOST_CANCEL_CARRIER_OUT = 1610, //  <<--- HOST : S3F17, CancelCarrierOut
	EVENT_GEMDLL_CMS_HOST_CARRIER_IN = 1611, //  <<--- HOST : S3F17, CarrierIn
	EVENT_GEMDLL_CMS_HOST_CARRIER_NOTIFICATION = 1612, //  <<--- HOST : S3F17, CarrierNotification
	EVENT_GEMDLL_CMS_HOST_CARRIER_OUT = 1613, //  <<--- HOST : S3F17, CarrierOut
	EVENT_GEMDLL_CMS_HOST_CARRIER_RELEASE = 1614, //  <<--- HOST : S3F17, CarrierRelease
	EVENT_GEMDLL_CMS_HOST_CARRIER_RECREATE	= 1615, //  <<--- HOST : S3F17, CarrierReCreate

	EVENT_GEMDLL_CMS_HOST_SET_ACCESSMODE_CHANGE = 1701,	//	<<--- HOST : S3F27, CHANGEACCESS MODE : MANUAL
	EVENT_GEMDLL_CMS_HOST_SET_PORTSERVICE_CHANGE = 1702, //  <<--- HOST : S3F25, CHANGESERVICESTATUS (PORTID, IN_OUT)

	EVENT_GEMDLL_PJM_HOST_SET_PRJOB_CREATE = 1801,	//  <<--- HOST : S16F11/15, PRJob(Multi)Create
	EVENT_GEMDLL_PJM_HOST_SET_PRJOB_DEQUE = 1802, //  <<--- HOST : S16F17, PRJobSetDeque
	EVENT_GEMDLL_PJM_HOST_SET_PRJOB_RECIPE_VAL = 1803, //  <<--- HOST : S16F23, PRJobSetRevipeVariable
	EVENT_GEMDLL_PJM_HOST_SET_PRJOB_STARTMETHOD = 1804,	//	<<--- HOST : S16F25, PRJobSetStartMethod
	EVENT_GEMDLL_PJM_HOST_SET_PRJOB_COMMAND = 1805,	//  <<--- HOST : S16F5,  PrJobCommandRequest
	EVENT_GEMDLL_PJM_EQ_CREATE_PRJOB = 1809,

	EVENT_GEMDLL_CJM_HOST_SET_CONTROLJOB_CREATE = 1901,	//	<<--- HOST : S14F9,  CreateObjectRequest (CJ)
	EVENT_GEMDLL_CJM_HOST_SET_CONTROLJOB_DELETE = 1902,	//  <<--- HOST : S14F11, DeleteObjectRequest (CJ)
	EVENT_GEMDLL_CJM_HOST_SET_CTRLJOB_COMMAND = 1905,	//  <<--- HOST : S16F27, CtrlJobCommand
	EVENT_GEMDLL_CJM_EQ_CREATE_CONTROLJOB = 1909,

	EVENT_GEMDLL_STS_HOST_SET_SUBST_CREATE = 2001, //  <<--- HOST : S14F9,  CreateObjectRequest (Substrate)
	EVENT_GEMDLL_STS_HOST_SET_SUBST_DELETE = 2002, //  <<--- HOST : S14F11, DeleteObjectRequest (Substrate)
	EVENT_GEMDLL_STS_HOST_SET_PROCEED_SUBST = 2003, //  <<--- HOST : S14F19, GenericServiceRequest
	EVENT_GEMDLL_STS_HOST_SET_CANCEL_SUBST = 2004, //  <<--- HOST : S14F19, GenericServiceRequest

	EVENT_GEMDLL_EXPIRED = 9999,
};

#include <string>

extern "C"
{
	__declspec(dllimport)  EZGEMCLASS  EZGEM_CreateClass();
	__declspec(dllimport)  void  EZGEM_DeleteClass(EZGEMCLASS);

	__declspec(dllimport)  void   EZGEM_SetEventHandler(EZGEMCLASS pGem, LPVOID lpHandle, pNativeCallBackEvent cb);
	__declspec(dllimport)  void   EZGEM_SetMsgHandler(EZGEMCLASS pGem, LPVOID lpHandle, pNativeCallBackMsg cb);
	__declspec(dllimport)  short  EZGEM_Start(EZGEMCLASS pGem);
	__declspec(dllimport)  short  EZGEM_Stop(EZGEMCLASS pGem);
	__declspec(dllimport)  long   EZGEM_CreateMsg(EZGEMCLASS pGem, short nStream, short nFunction, short nWbit);
	__declspec(dllimport)  long   EZGEM_CreateReplyMsg(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_SendMsg(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_SendMsgEx(EZGEMCLASS pGem, long lMsgId, long nTransactionID);
	__declspec(dllimport)  short  EZGEM_CloseMsg(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_GetMsgInfo(EZGEMCLASS pGem, long lMsgId, short *pnStream, short * pnFunction, short * pnWbit, long * plLength);

	__declspec(dllimport)  short  EZGEM_GetDeviceID(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetDeviceID(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetPassiveMode(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetPassiveMode(EZGEMCLASS pGem, short bNewValue);
	__declspec(dllimport)  BSTR   EZGEM_GetIP(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetIP(EZGEMCLASS pGem, LPCTSTR lpszNewValue);
	__declspec(dllimport)  short  EZGEM_GetPort(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetPort(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetT3(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetT3(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetT5(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetT5(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetT6(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetT6(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetT7(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetT7(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetT8(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetT8(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetRetry(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetRetry(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetLinkTestInterval(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetLinkTestInterval(EZGEMCLASS pGem, short nNewValue);
	__declspec(dllimport)  short  EZGEM_GetRuntimeState(EZGEMCLASS pGem);

	__declspec(dllimport)  short  EZGEM_OpenListItem(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_CloseListItem(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_AddBinaryItem(EZGEMCLASS pGem, long lMsgId, short * pValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddByteItem(EZGEMCLASS pGem, long lMsgId, BYTE * pValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddAsciiItem(EZGEMCLASS pGem, long lMsgId, LPCTSTR pszValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddBoolItem(EZGEMCLASS pGem, long lMsgId, short * pValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddI1Item(EZGEMCLASS pGem, long lMsgId, short * pValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddI2Item(EZGEMCLASS pGem, long lMsgId, short * pValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddI4Item(EZGEMCLASS pGem, long lMsgId, long * plValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddI8Item(EZGEMCLASS pGem, long lMsgId, long * plValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddI8ItemI64(EZGEMCLASS pGem, long lMsgId, LONGLONG * plValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddU1Item(EZGEMCLASS pGem, long lMsgId, short * pValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddU2Item(EZGEMCLASS pGem, long lMsgId, long * plValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddU4Item(EZGEMCLASS pGem, long lMsgId, double * prValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddU8Item(EZGEMCLASS pGem, long lMsgId, double * prValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddU8ItemU64(EZGEMCLASS pGem, long lMsgId, ULONGLONG * prValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddF4Item(EZGEMCLASS pGem, long lMsgId, float * prValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddF8Item(EZGEMCLASS pGem, long lMsgId, double * prValue, long lCount);
	__declspec(dllimport)  short  EZGEM_AddJ8Item(EZGEMCLASS pGem, long lMsgId, LPCTSTR pszValue, long lCount);
	__declspec(dllimport)  short  EZGEM_GetMsgInfo(EZGEMCLASS pGem, long lMsgId, short * pnStream, short * pnFunction, short * pnWbit, long * plLength);
	__declspec(dllimport)  short  EZGEM_GetListItemOpen(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_GetListItemClose(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_GetAsciiItem(EZGEMCLASS pGem, long lMsgId, BSTR * pszValue);
	__declspec(dllimport)  long   EZGEM_GetJ8Item(EZGEMCLASS pGem, long lMsgId, BSTR * pszValue);
	__declspec(dllimport)  long   EZGEM_GetBinaryItem(EZGEMCLASS pGem, long lMsgId, short * pnValue);
	__declspec(dllimport)  long   EZGEM_GetByteItem(EZGEMCLASS pGem, long lMsgId, BYTE * pnValue);
	__declspec(dllimport)  long   EZGEM_GetBoolItem(EZGEMCLASS pGem, long lMsgId, short * pnValue);
	__declspec(dllimport)  long   EZGEM_GetI1Item(EZGEMCLASS pGem, long lMsgId, short * pnValue);
	__declspec(dllimport)  long   EZGEM_GetI2Item(EZGEMCLASS pGem, long lMsgId, short * pnValue);
	__declspec(dllimport)  long   EZGEM_GetI4Item(EZGEMCLASS pGem, long lMsgId, long * plValue);
	__declspec(dllimport)  long   EZGEM_GetI8Item(EZGEMCLASS pGem, long lMsgId, long * plValue);
	__declspec(dllimport)  long   EZGEM_GetI8ItemI64(EZGEMCLASS pGem, long lMsgId, LONGLONG * plValue);
	__declspec(dllimport)  long   EZGEM_GetU1Item(EZGEMCLASS pGem, long lMsgId, short * pnValue);
	__declspec(dllimport)  long   EZGEM_GetU2Item(EZGEMCLASS pGem, long lMsgId, long * plValue);
	__declspec(dllimport)  long   EZGEM_GetU4Item(EZGEMCLASS pGem, long lMsgId, double * prValue);
	__declspec(dllimport)  long   EZGEM_GetU8Item(EZGEMCLASS pGem, long lMsgId, double * prValue);
	__declspec(dllimport)  long   EZGEM_GetU8ItemU64(EZGEMCLASS pGem, long lMsgId, ULONGLONG * prValue);
	__declspec(dllimport)  long   EZGEM_GetF4Item(EZGEMCLASS pGem, long lMsgId, float * prValue);
	__declspec(dllimport)  long   EZGEM_GetF8Item(EZGEMCLASS pGem, long lMsgId, double * prValue);
	__declspec(dllimport)  void   EZGEM_SetLogFile(EZGEMCLASS pGem, LPCTSTR strFileName, short bLogSecsII);
	__declspec(dllimport)  long   EZGEM_GetCurLogFile(EZGEMCLASS pGem, BSTR *psCurLogFile);
	__declspec(dllimport)  short  EZGEM_GetNextItemFormat(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_GetSubItemFormat(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_GetNextItemCount(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_GetSubItemCount(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  short  EZGEM_AbortMsg(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  void   EZGEM_SetLogRetention(EZGEMCLASS pGem, short nDays);
	__declspec(dllimport)  short  EZGEM_GetLogRetention(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetFormatCheck(EZGEMCLASS pGem, short bEnabled);
	__declspec(dllimport)  short  EZGEM_GetFormatCheck(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SetFormatFile(EZGEMCLASS pGem, LPCTSTR lpszFormatFile);
	__declspec(dllimport)  long   EZGEM_AddFileBinaryItem(EZGEMCLASS pGem, long lMsgId, LPCTSTR szFile);
	__declspec(dllimport)  long   EZGEM_GetFileBinaryItem(EZGEMCLASS pGem, long lMsgId, LPCTSTR szFile);
	__declspec(dllimport)  long   EZGEM_GetMsgHead(EZGEMCLASS pGem, long lMsgId, UCHAR *pnByteBuff);
	__declspec(dllimport)  long   EZGEM_GetMsgBody(EZGEMCLASS pGem, long lMsgId, UCHAR *pnByteBuff, long lSize);
	__declspec(dllimport)  void   EZGEM_EnableErrorMessage(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_DisableErrorMessage(EZGEMCLASS pGem);
	__declspec(dllimport)  short  EZGEM_AddListItem(EZGEMCLASS pGem, long lMsgId, long lCount);
	__declspec(dllimport)  long   EZGEM_GetListItem(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  void   EZGEM_SetConfigFile(EZGEMCLASS pGem, LPCTSTR strConfigFile);
	__declspec(dllimport)  void   EZGEM_SaveConfigFile(EZGEMCLASS pGem, LPCTSTR strConfigFile);
	__declspec(dllimport)  short  EZGEM_SeparateLog(EZGEMCLASS pGem, LPCTSTR szLogFileName, short nStream, short nFunction);
	__declspec(dllimport)  void   EZGEM_SetMaxLogFileSize(EZGEMCLASS pGem, short nMegaByte);
	__declspec(dllimport)  short  EZGEM_SetLogDelTime(EZGEMCLASS pGem, long nDelTime);
	__declspec(dllimport)  long   EZGEM_SetMsgHead(EZGEMCLASS pGem, long lMsgId, UCHAR *pnBuff);
	__declspec(dllimport)  long   EZGEM_SetMsgBody(EZGEMCLASS pGem, long lMsgId, UCHAR *pnBuff, long lSize);
	__declspec(dllimport)  long   EZGEM_AddArrayItem(EZGEMCLASS pGem, long lMsgId, LPCTSTR pszType, long nDataCount, LPCTSTR pszData);
	__declspec(dllimport)  long   EZGEM_GetArrayItem(EZGEMCLASS pGem, long lMsgId, BSTR * pszValue);
	__declspec(dllimport)  void   EZGEM_EnableLog(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_DisableLog(EZGEMCLASS pGem);
	__declspec(dllimport)  void   EZGEM_SkipLog(EZGEMCLASS pGem, short nStream, short nFunction);
	__declspec(dllimport)  void   EZGEM_SkipLogReset(EZGEMCLASS pGem, short nStream, short nFunction);
	__declspec(dllimport)  void   EZGEM_WriteUserLog(EZGEMCLASS pGem, LPCTSTR pszLog);
	__declspec(dllimport)  long   EZGEM_GetNextEvent(EZGEMCLASS pGem, short  *pnEventID, long  *plParam);
	__declspec(dllimport)  long   EZGEM_GetNextMsg(EZGEMCLASS pGem, long  *plMsgId);
	__declspec(dllimport)  short  EZGEM_GetMsgQueSize(EZGEMCLASS pGem);
	__declspec(dllimport)  long   EZGEM_GetSysByte(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_GetSysByteEx(EZGEMCLASS pGem, long nTransactionID);
	__declspec(dllimport)  long   EZGEM_GetItem(EZGEMCLASS pGem, long lMsgId, BSTR *pstrValue);
	__declspec(dllimport)  long   EZGEM_SaveMsgToFile(EZGEMCLASS pGem, long lMsgId, LPCTSTR sFile);
	__declspec(dllimport)  long   EZGEM_SendMsgFromFile(EZGEMCLASS pGem, LPCTSTR sFile);
	__declspec(dllimport)  long   EZGEM_GetListChildItem(EZGEMCLASS pGem, long lMsgId, LPCTSTR sDelimiter,  BSTR *pszValue, long *plLength);
	__declspec(dllimport)  long   EZGEM_GetNameValueListItem(EZGEMCLASS pGem, long lMsgId, LPCTSTR sDelimiter, BSTR *pszNameList, BSTR *pszValueList, long *plLength);
	__declspec(dllimport)  long   EZGEM_SendS9F3(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_SendS9F5(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_SendS9F7(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long   EZGEM_SendS9F11(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  void   EZGEM_GetVersionInfo(EZGEMCLASS pGem, BSTR *psVersionInfo);
	__declspec(dllimport)  long   EZGEM_GetItemInfo(EZGEMCLASS pGem, long lMsgId, LPCTSTR sPos, short *pnFormat, long *plCount);
	__declspec(dllimport)  long   EZGEM_GetItemValue(EZGEMCLASS pGem, long lMsgId, LPCTSTR sPos, BSTR *psValue);
	__declspec(dllimport)  long   EZGEM_SetOption(EZGEMCLASS pGem, LPCTSTR sOptionName, int nOptionVal);
	//--------------------------------- END OF EZNET FUNCTION ------------------------------------------------------------
	__declspec(dllimport)  void  EZGEM_SetCommRequestTime(EZGEMCLASS pGem, short nTimerCR);
	__declspec(dllimport)  short EZGEM_GetCommRequestTime(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_SetModelName(EZGEMCLASS pGem, const char *lpszModelName);
	__declspec(dllimport)  void  EZGEM_SetSoftRev(EZGEMCLASS pGem, const char *lpszSoftRev);
	__declspec(dllimport)  void  EZGEM_GoOffline(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_GoOnlineLocal(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_GoOnlineRemote(EZGEMCLASS pGem);
	__declspec(dllimport)  long  EZGEM_AddCEID(EZGEMCLASS pGem, long CEID, const char *pszName, const char *pszDescription);
	__declspec(dllimport)  long  EZGEM_AddSVID(EZGEMCLASS pGem, long SVID, const char *pszName, const char *pszFormat, const char *pszUnit);
	__declspec(dllimport)  long  EZGEM_AddDVID(EZGEMCLASS pGem, long DVID, const char *pszName, const char *pszFormat);
	__declspec(dllimport)  long  EZGEM_AddALID(EZGEMCLASS pGem, long ALID, const char *pszName, const char *pszALCD);
	__declspec(dllimport)  long  EZGEM_AddECID(EZGEMCLASS pGem, long ECID, const char *pszName, const char *pszUnit, const char *pszFormat);
	__declspec(dllimport)  long  EZGEM_AddRemoteCommand(EZGEMCLASS pGem, const char *pszCommand);
	__declspec(dllimport)  short EZGEM_GetRemoteCommand(EZGEMCLASS pGem, long lMsgId, BSTR  *pstrCommandName);
	__declspec(dllimport)  short EZGEM_GetRemoteCommandParam(EZGEMCLASS pGem, long lMsgId, short nIndex, BSTR  *pstrName, BSTR  *pstrValue, short *pnFormat);
	__declspec(dllimport)  short EZGEM_ReplyRemoteCommand(EZGEMCLASS pGem, long lMsgId, short HCACK);
	__declspec(dllimport)  short EZGEM_SendEventReport(EZGEMCLASS pGem, long CEID);
	__declspec(dllimport)  short EZGEM_SendEventReportEx(EZGEMCLASS pGem, long CEID, long nTransactionID);
	__declspec(dllimport)  short EZGEM_SendAlarmReport(EZGEMCLASS pGem, long ALID, short ALCD);
	__declspec(dllimport)  short EZGEM_SendAlarmReportEx(EZGEMCLASS pGem, long ALID, short ALCD, short nMode);
	__declspec(dllimport)  long  EZGEM_DisableAutoReply(EZGEMCLASS pGem, short nStream, short nFunction);
	__declspec(dllimport)  long  EZGEM_EnableAutoReply(EZGEMCLASS pGem, short nStream, short nFunction);
	__declspec(dllimport)  long  EZGEM_SetSVIDValue(EZGEMCLASS pGem, long SVID, const char *pszValue);
	__declspec(dllimport)  long  EZGEM_SetVIDValue(EZGEMCLASS pGem, long VID, const char *pszValue);
	__declspec(dllimport)  short EZGEM_GetSVIDValue(EZGEMCLASS pGem, long SVID, BSTR  *pstrCurrentValue);
	__declspec(dllimport)  long  EZGEM_GetSVID(EZGEMCLASS pGem, long SVID, short  *pnFormat, BSTR  *pstrName);
	__declspec(dllimport)  short EZGEM_GetHostSetECID(EZGEMCLASS pGem, long lMsgId, long *lpECID, BSTR *pstrNewValue);
	__declspec(dllimport)  short EZGEM_SetECValue(EZGEMCLASS pGem, long ECID, const char *pszValue);
	__declspec(dllimport)  long  EZGEM_GetECValue(EZGEMCLASS pGem, long ECID, BSTR  *pstrValue);
	__declspec(dllimport)  short EZGEM_SetECRange(EZGEMCLASS pGem, long ECID, const char *pszMinValue, const char *pszMaxValue);
	__declspec(dllimport)  short EZGEM_ReplyHostSetECID(EZGEMCLASS pGem, long lMsgId, short EAC);
	__declspec(dllimport)  void  EZGEM_EnableSpooling(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_DisableSpooling(EZGEMCLASS pGem);
	__declspec(dllimport)  long  EZGEM_GetSpoolCount(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_SetMaxSpoolCount(EZGEMCLASS pGem, UINT nMaxSpoolCount);
	__declspec(dllimport)  long  EZGEM_GetMaxSpoolCount(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_SetMaxSpoolTransmitCount(EZGEMCLASS pGem, UINT nMaxSpoolTransmit);
	__declspec(dllimport)  long  EZGEM_GetMaxSpoolTransmitCount(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_EnableSpoolOverwrite(EZGEMCLASS pGem);
	__declspec(dllimport)  void  EZGEM_DisableSpoolOverwrite(EZGEMCLASS pGem);
	__declspec(dllimport)  long  EZGEM_GetTerminalMsg(EZGEMCLASS pGem, long lMsgId, short *pnTID, BSTR  *pstrMsg);
	__declspec(dllimport)  void  EZGEM_SetReportFilePath(EZGEMCLASS pGem, const char *pszFilePath);
	__declspec(dllimport)  long  EZGEM_AddStatusValueToMsg(EZGEMCLASS pGem, long lMsgId, long SVID);
	__declspec(dllimport)  long  EZGEM_SetTimeFormat(EZGEMCLASS pGem, short nTimeFormat);
	__declspec(dllimport)  short EZGEM_SetFormatCode(EZGEMCLASS pGem, const char *szItemName, const char *szFormatCode);
	__declspec(dllimport)  void  EZGEM_GetSpoolTime(EZGEMCLASS pGem, BSTR  *pstrStartTime, BSTR  *pstrFullTime);
	__declspec(dllimport)  long  EZGEM_GetAlarmInfo(EZGEMCLASS pGem, long ALID, short  *pnALCD, BSTR  *pstrText);
	__declspec(dllimport)  BSTR  EZGEM_GetAlarmText(EZGEMCLASS pGem, long ALID);
	__declspec(dllimport)  short EZGEM_GetAlarmCode(EZGEMCLASS pGem, long ALID);
	__declspec(dllimport)  long  EZGEM_GetAlarmState(EZGEMCLASS pGem, long ALID);
	__declspec(dllimport)  void  EZGEM_SetRemoteCommandErrorCode(EZGEMCLASS pGem, long lMsgId, LPCTSTR szCommand, short nParamIndex, short nErrorCode);
	__declspec(dllimport)  long  EZGEM_ResetMsgReceived(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport)  long  EZGEM_WriteEZGemStatus(EZGEMCLASS pGem);
	__declspec(dllimport)  long  EZGEM_GetReport(EZGEMCLASS pGem, long RPTID, long *plSVID);
	__declspec(dllimport)  long  EZGEM_GetEventReport(EZGEMCLASS pGem, long CEID, long *plRPTID);
	__declspec(dllimport)  long  EZGEM_GetTraceInfo(EZGEMCLASS pGem, long TRID, long *plSampleCount, long *plVidCount, BSTR *pstrVidList, BSTR *pstrPeriod);
	//------------------------------------------------------------------------------------------
	// 	GEM300 API
	__declspec(dllimport) long EZGEM_Set300IniFile(LPCTSTR szFileName);
	//  CMS
	__declspec(dllimport) long EZGEM_SetLoadPort(EZGEMCLASS pGem, int nPortID, int nTransferState, int nAccessMode, LPCTSTR strLocationName, LPCTSTR strCarrierID);
	__declspec(dllimport) long EZGEM_SetTransferState(EZGEMCLASS pGem, int nPortID, int nTransferState);
	__declspec(dllimport) long EZGEM_SetCarrierArrived(EZGEMCLASS pGem, int nPortID);
	__declspec(dllimport) long EZGEM_SetCarrierRemoved(EZGEMCLASS pGem, int nPortID);
	__declspec(dllimport) long EZGEM_SetDoorState(EZGEMCLASS pGem, int nPortID, int nState);
	__declspec(dllimport) long EZGEM_SetDockState(EZGEMCLASS pGem, int nPortID, int nState);
	__declspec(dllimport) long EZGEM_SetClampState(EZGEMCLASS pGem, int nPortID, int nState);
	__declspec(dllimport) long EZGEM_SetLoadPortAccessMode(EZGEMCLASS pGem, int nPortID, int nMode);
	__declspec(dllimport) long EZGEM_SetCarrierAccessState(EZGEMCLASS pGem, int nPortID, int nState, LPCTSTR strCarrierID);
	__declspec(dllimport) long EZGEM_SetCarrierIDRead(EZGEMCLASS pGem, int nPortID, LPCTSTR strCarrierID, int nResult);
	__declspec(dllimport) long EZGEM_SetCarrierIDStatus(EZGEMCLASS pGem, int nPortID, LPCTSTR strCarrierID, int nStatus);
	__declspec(dllimport) long EZGEM_SetSlotMapRead(EZGEMCLASS pGem, int nPortID, LPCTSTR strCarrierID, LPCTSTR strSlotMap, int nResult);
	__declspec(dllimport) long EZGEM_SetSlotMapStatus(EZGEMCLASS pGem, int nPortID, LPCTSTR strCarrierID, int nStatus);
	__declspec(dllimport) long EZGEM_GetCarrierActionInfo(EZGEMCLASS pGem, long lMsgId, int *pnPortID, BSTR *pstrCarrierID, int *pnContentMapCount, int *pnSlotMapCount);
	__declspec(dllimport) long EZGEM_GetContentMapInfo(EZGEMCLASS pGem, long lMsgId, int nIndex, BSTR *pstrContentMap);
	__declspec(dllimport) long EZGEM_GetSlotMapInfo(EZGEMCLASS pGem, long lMsgId, BSTR *pstrSlotMap);
	__declspec(dllimport) long EZGEM_GetHostSetLoadPortAccessMode(EZGEMCLASS pGem, long lMsgId, int *pnAccessMode, BSTR *pstrPortList);
	__declspec(dllimport) long EZGEM_GetHostSetLoadPortServiceMode(EZGEMCLASS pGem, long lMsgId, int *pnServiceMode, BSTR *pstrPortList);
	__declspec(dllimport) long EZGEM_ReplyCarrierAction(EZGEMCLASS pGem, long lMsgId, int CAACK);
	__declspec(dllimport) long EZGEM_SetCarrierActionErrorCode(EZGEMCLASS pGem, long lMsgId, int nErrorCode, LPCTSTR strErrorText);
	__declspec(dllimport) long EZGEM_DeleteCarrier(EZGEMCLASS pGem, LPCTSTR sCarrierID);
	__declspec(dllimport) long EZGEM_DeleteAllCarrier(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetLoadPortInfo(EZGEMCLASS pGem, int nPortID, BSTR *psLocID, BSTR *psCarrierID, int *pnAccessMode, int *pnTransferState, int *pnReservState, int *pnAssocState);
	__declspec(dllimport) long EZGEM_GetCarrierInfo(EZGEMCLASS pGem, LPCTSTR szCarrierID, BSTR *psLocID, int *pnIDStatus, int *pnSlotMapStatus, int *pnAccessStatus, BSTR *pstrSlotMap, BSTR *psUsage);
	__declspec(dllimport) long EZGEM_GetSlotInfo(EZGEMCLASS pGem, LPCTSTR szCarrierID, int nSlotNo, int *pnSlotType, BSTR *psLotID, BSTR *psSubstID);
	__declspec(dllimport) long EZGEM_CreateCarrierLoc(EZGEMCLASS pGem, LPCTSTR szLocationID);
	__declspec(dllimport) long EZGEM_SetCarrierLocInfo(EZGEMCLASS pGem, LPCTSTR szLocationID, LPCTSTR szCarrierID);
	__declspec(dllimport) long EZGEM_GetCarrierLocInfo(EZGEMCLASS pGem, LPCTSTR szLocationID, BSTR *psCarrierID);
	__declspec(dllimport) long EZGEM_GetCarrierLocation(EZGEMCLASS pGem, LPCTSTR szCarrierID, BSTR *psLocationID);
	__declspec(dllimport) long EZGEM_SetCarrierMove(EZGEMCLASS pGem, LPCTSTR szCarrierID, LPCTSTR szLocationID);
	__declspec(dllimport) long EZGEM_GetCarrierCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetCarrierList(EZGEMCLASS pGem, long nIndex, BSTR *psCarrierID, BSTR *psLocID);
	__declspec(dllimport) long EZGEM_GetCarrierLocCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetCarrierLocList(EZGEMCLASS pGem, long nIndex, BSTR *psLocationID, BSTR *psCarrierID);
	__declspec(dllimport) long EZGEM_SetCarrierInternalBufferMode(EZGEMCLASS pGem, int nMode);

	// PJM
	__declspec(dllimport) long EZGEM_GetHostSetPrJobCount(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport) long EZGEM_GetHostSetPrJob(EZGEMCLASS pGem, long lMsgId, long nIndex, BSTR *pstrPrJobID, BSTR *pstrPPID, int *pnCarrierCount, int *pnAutoStart, int *pnParamCount);
	__declspec(dllimport) long EZGEM_GetHostSetPrJobStartMethod(EZGEMCLASS pGem, long lMsgId, int *pnPrJobCount, BSTR *pstrPrJobList, int *pnStartMethod);
	__declspec(dllimport) long EZGEM_GetHostSetPrJobParam(EZGEMCLASS pGem, long lMsgId, BSTR *pstrPrJob, int *pnParamCount);
	__declspec(dllimport) long EZGEM_GetPrJobCarrier(EZGEMCLASS pGem, LPCTSTR szPrJobID, long nIndex, BSTR *pstrCarrierID, BSTR *pstrSlotList);
	__declspec(dllimport) long EZGEM_GetPrJobParam(EZGEMCLASS pGem, LPCTSTR szPrJobID, long nIndex, BSTR *pstrParamName, BSTR *pstrParamVal);
	__declspec(dllimport) long EZGEM_GetPrJobRecipeMethod(EZGEMCLASS pGem, LPCTSTR szPrJobID, int *pnRecipeMethod);
	__declspec(dllimport) long EZGEM_GetPrJobCommand(EZGEMCLASS pGem, long lMsgId, BSTR *pstrPrJobID, BSTR *pstrCommand);
	__declspec(dllimport) long EZGEM_SetPrJobErrorCode(EZGEMCLASS pGem, long lMsgId, LPCTSTR szPrJobID, int nErrorCode, LPCTSTR szErrorText);
	__declspec(dllimport) long EZGEM_ReplyHostSetPrJob(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport) long EZGEM_ReplyPrJobCommand(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport) long EZGEM_GetPrJobCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetPrJobSpace(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetPrJob(EZGEMCLASS pGem, long nIndex, BSTR *pstrPrJobID, BSTR *pstrPPID, int *pnCarrierCount, int *pnAutoStart, int *pnParamCount);
	__declspec(dllimport) long EZGEM_GetPrJobInfo(EZGEMCLASS pGem, LPCTSTR szPrJobID, BSTR *pstrPPID, int *pnCarrierCount, int *pnAutoStart, int *pnParamCount);
	__declspec(dllimport) long EZGEM_GetPrJobDeleted(EZGEMCLASS pGem, BSTR *pstrPrJobID);
	__declspec(dllimport) long EZGEM_DeletePrJob(EZGEMCLASS pGem, LPCTSTR szPrJobID);
	__declspec(dllimport) long EZGEM_DeleteAllPrJob(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetPrJobState(EZGEMCLASS pGem, LPCTSTR szPrJobID, int *pnPrJobState);
	__declspec(dllimport) long EZGEM_SetPrJobState(EZGEMCLASS pGem, LPCTSTR szPrJobID, int nPrJobState);
	__declspec(dllimport) long EZGEM_CreatePrJob(EZGEMCLASS pGem, LPCTSTR sPrJobID, int nAutoStart, LPCTSTR sCarrierList, LPCTSTR sSlotList, LPCTSTR sPPID);
	__declspec(dllimport) long EZGEM_CreatePrJobSubst(EZGEMCLASS pGem, LPCTSTR sPrJobID, int nAutoStart, LPCTSTR sSubstrateList, LPCTSTR sPPID);
	__declspec(dllimport) long EZGEM_GetPrJobMaterialFormatCode(EZGEMCLASS pGem, LPCTSTR sPrJobID);
	__declspec(dllimport) long EZGEM_AddPrJobParam(EZGEMCLASS pGem, LPCTSTR szPrJobID, LPCTSTR szParamName, LPCTSTR szParamVal);
	// CJM
	__declspec(dllimport) long EZGEM_GetHostSetCtrlJob(EZGEMCLASS pGem, long lMsgId, BSTR *pstrCtrlJobID, int *pnPrJobCount, int *pnAutoStart); 
	__declspec(dllimport) long EZGEM_GetCtrlJob(EZGEMCLASS pGem, long nIndex, BSTR *pstrCtrlJobID, int *pnPrJobCount, int *pnAutoStart);
	__declspec(dllimport) long EZGEM_GetCtrlJobInfo(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, int *pnPrJobCount, int *pnAutoStart);
	__declspec(dllimport) long EZGEM_GetCtrlJobMtrlOutMapCount(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, int *pnMtrlOutMapCount);
	__declspec(dllimport) long EZGEM_GetCtrlJobMtrlOutInfo(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, int nMapIndex, BSTR *pstrSrcCarrier, BSTR *pstrSrcSlotList, BSTR *pstrDestCarrier, BSTR *pstrDestSlotList);
	__declspec(dllimport) long EZGEM_GetPrJobInCtrlJob(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, int nIndex, BSTR *pstrPrJobID);
	__declspec(dllimport) long EZGEM_GetCtrlJobCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetCtrlJobSpace(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetCtrlJobCommand(EZGEMCLASS pGem, long lMsgId, BSTR *pstrCJobID, int *pnCommand);
	__declspec(dllimport) long EZGEM_GetCtrlJobDeleted(EZGEMCLASS pGem, BSTR *pstrCJobID);
	__declspec(dllimport) long EZGEM_ReplyCtrlJob(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport) long EZGEM_ReplyCtrlJobCommand(EZGEMCLASS pGem, long lMsgId);
	__declspec(dllimport) long EZGEM_SetCtrlJobErrorCode(EZGEMCLASS pGem, long lMsgId, int nErrorCode, LPCTSTR szErrorText);
	__declspec(dllimport) long EZGEM_DeleteCtrlJob(EZGEMCLASS pGem, LPCTSTR szCtrlJobID);
	__declspec(dllimport) long EZGEM_DeleteAllCtrlJob(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_SetCtrlJobState(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, int nState);
	__declspec(dllimport) long EZGEM_GetCtrlJobState(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, int *pnState);
	__declspec(dllimport) long EZGEM_CreateCtrlJob(EZGEMCLASS pGem, LPCTSTR sCtrlJobID, LPCTSTR sPrJobList, int nAutoStat);
	__declspec(dllimport) long EZGEM_AddCtrlJobCarrierInputSpec(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, LPCTSTR szCarrierID);
	__declspec(dllimport) long EZGEM_AddCtrlJobMtrlOutSpec(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, LPCTSTR szSrcCarrierID, LPCTSTR szSrcSlotList, LPCTSTR szDestCarrierID, LPCTSTR szDestSlotList);
	__declspec(dllimport) long EZGEM_GetCtrlJobCarrierInputSpec(EZGEMCLASS pGem, LPCTSTR szCtrlJobID, BSTR *bstrCarrerList);
	// STS
	__declspec(dllimport) long EZGEM_CreateSubstLoc(EZGEMCLASS pGem, LPCTSTR sLocID);
	__declspec(dllimport) long EZGEM_CreateSubstBatchLoc(EZGEMCLASS pGem, LPCTSTR sBatchLocID);
	__declspec(dllimport) long EZGEM_CreateSubstrate(EZGEMCLASS pGem, LPCTSTR sSubstID);
	__declspec(dllimport) long EZGEM_GetSubstLocCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetSubstBatchLocCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetSubstrateCount(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_GetSubstrate(EZGEMCLASS pGem, long nIndex, BSTR *psSubstID, BSTR *psCurrentLoc);
	__declspec(dllimport) long EZGEM_GetSubstrateState(EZGEMCLASS pGem, LPCTSTR sSubstID, int *pnTranState, int *pnProcState, int *pnReadState);
	__declspec(dllimport) long EZGEM_GetSubstLocation(EZGEMCLASS pGem, long nIndex, BSTR *psLocID, BSTR *psSubstID, int *pnLocState);
	__declspec(dllimport) long EZGEM_GetSubstBatchLoc(EZGEMCLASS pGem, long nIndex, BSTR *psBatchLocID, int *pnSubstCount, char *psSubstList[]);
	__declspec(dllimport) long EZGEM_GetSubstHostCommand(EZGEMCLASS pGem, long lMsgId, int *pnCommand, BSTR *psSubstID, BSTR *psLocID);
	__declspec(dllimport) long EZGEM_DeleteAllSubstrate(EZGEMCLASS pGem);
	__declspec(dllimport) long EZGEM_DeleteSubstrate(EZGEMCLASS pGem, LPCTSTR sSubstID);
	__declspec(dllimport) long EZGEM_SetSubstrateMove(EZGEMCLASS pGem, LPCTSTR sSubstID, LPCTSTR sToLocID, int nTransferState);
	__declspec(dllimport) long EZGEM_SetSubstBatchMove(EZGEMCLASS pGem, int nCount, BSTR *psSubstList, LPCTSTR sBatchLocID, int nStartPosInBatch, int nTransState);
	__declspec(dllimport) long EZGEM_SetSubstTranState(EZGEMCLASS pGem, LPCTSTR sSubstID, int nTranState);
	__declspec(dllimport) long EZGEM_SetSubstProcState(EZGEMCLASS pGem, LPCTSTR sSubstID, int nProcState);
	__declspec(dllimport) long EZGEM_SetSubstReadState(EZGEMCLASS pGem, LPCTSTR sSubstID, int nReadState);
	__declspec(dllimport) long EZGEM_SetSubstIDRead(EZGEMCLASS pGem, LPCTSTR sSubstID, LPCTSTR sReadID, int nReadResult);
	__declspec(dllimport) long EZGEM_ReplySubstAction(EZGEMCLASS pGem, long lMsgId, int nRetCode, int nErrCode, LPCTSTR szErrText);
	__declspec(dllimport) long EZGEM_SetSubstLocState(EZGEMCLASS pGem, LPCTSTR sLocID, int nLocState);
	// OSS
	__declspec(dllimport) long EZGEM_GetAttrName(EZGEMCLASS pGem, LPCTSTR sObjType, BSTR *psAttrNameList);
	__declspec(dllimport) long EZGEM_GetAttrData(EZGEMCLASS pGem, LPCTSTR sObjType, LPCTSTR sObjID, LPCTSTR sObjName, BSTR *psAttrData);
	__declspec(dllimport) long EZGEM_SetAttrData(EZGEMCLASS pGem, LPCTSTR sObjType, LPCTSTR sObjID, LPCTSTR sObjName, LPCTSTR psAttrData);
	__declspec(dllimport) long EZGEM_GetObjectList(EZGEMCLASS pGem, LPCTSTR sObjType, BSTR *psObjList);
};

#include <vector>
#include <iostream>
#include <sstream>
using namespace std;

class EZGemPlus
{
private:
	EZGEMCLASS pGEM;
public:
	EZGemPlus() { pGEM = EZGEM_CreateClass(); }
	//~EZGemPlus()	{ EZGEM_DeleteClass(pGEM); }

	short Start() { return EZGEM_Start(pGEM); }
	short Stop() { return EZGEM_Stop(pGEM); }

	void  SetEventHandler(void* lpHandle, pNativeCallBackEvent cb) { EZGEM_SetEventHandler(pGEM, lpHandle, cb); }
	void  SetMsgHandler(void* lpHandle, pNativeCallBackMsg cb) { EZGEM_SetMsgHandler(pGEM, lpHandle, cb); }

	void  SetPassiveMode(short bNewValue) { EZGEM_SetPassiveMode(pGEM, bNewValue); }
	short GetPassiveMode() { return EZGEM_GetPassiveMode(pGEM); }

	long  CreateMsg(short nStream, short nFunction, short nWbit) { return EZGEM_CreateMsg(pGEM, nStream, nFunction, nWbit); }
	long  CreateReplyMsg(long lMsgId) { return EZGEM_CreateReplyMsg(pGEM, lMsgId); }
	short SendMsg(long lMsgId) { return EZGEM_SendMsg(pGEM, lMsgId); }
	short SendMsgEx(long lMsgId, long nTransactionID) { return EZGEM_SendMsgEx(pGEM, lMsgId, nTransactionID); }
	short CloseMsg(long lMsgId) { return EZGEM_CloseMsg(pGEM, lMsgId); }
	short GetMsgInfo(long lMsgId, short * pnStream, short * pnFunction, short * pnWbit, long * plLength)
	{
		return EZGEM_GetMsgInfo(pGEM, lMsgId, pnStream, pnFunction, pnWbit, plLength);
	}
	short  GetDeviceID() { return EZGEM_GetDeviceID(pGEM); }
	void  SetDeviceID(short nNewValue) { EZGEM_SetDeviceID(pGEM, nNewValue); }
	BSTR  GetIP() { return EZGEM_GetIP(pGEM); }
//	void  SetIP(LPCTSTR lpszNewValue) { EZGEM_SetIP(pGEM, lpszNewValue); }
	short  GetPort() { return EZGEM_GetPort(pGEM); }
	void  SetPort(short nNewValue) { EZGEM_SetPort(pGEM, nNewValue); }
	short GetT3() { return EZGEM_GetT3(pGEM); }
	void  SetT3(short nNewValue) { EZGEM_SetT3(pGEM, nNewValue); }
	short GetT5() { return EZGEM_GetT5(pGEM); }
	void  SetT5(short nNewValue) { EZGEM_SetT5(pGEM, nNewValue); }
	short GetT6() { return EZGEM_GetT6(pGEM); }
	void  SetT6(short nNewValue) { EZGEM_SetT6(pGEM, nNewValue); }
	short GetT7() { return EZGEM_GetT7(pGEM); }
	void  SetT7(short nNewValue) { EZGEM_SetT7(pGEM, nNewValue); }
	short GetT8() { return EZGEM_GetT8(pGEM); }
	void  SetT8(short nNewValue) { EZGEM_SetT8(pGEM, nNewValue); }
	short GetRetry() { return EZGEM_GetRetry(pGEM); }
	void  SetRetry(short nNewValue) { EZGEM_SetRetry(pGEM, nNewValue); }
	short GetLinkTestInterval() { return EZGEM_GetLinkTestInterval(pGEM); }
	void  SetLinkTestInterval(short nNewValue) { EZGEM_SetLinkTestInterval(pGEM, nNewValue); }
	short GetRuntimeState() { return EZGEM_GetRuntimeState(pGEM); }
	short OpenListItem(long lMsgId) { return EZGEM_OpenListItem(pGEM, lMsgId); }
	short CloseListItem(long lMsgId) { return EZGEM_CloseListItem(pGEM, lMsgId); }
	short AddBinaryItem(long lMsgId, short * pValue, long lCount) { return EZGEM_AddBinaryItem(pGEM, lMsgId, pValue, lCount); }
	short AddBinaryItem(long lMsgId, BYTE * pValue, long lCount) { return EZGEM_AddByteItem(pGEM, lMsgId, pValue, lCount); }
//	short AddAsciiItem(long lMsgId, LPCTSTR pszValue, long lCount) { return EZGEM_AddAsciiItem(pGEM, lMsgId, pszValue, lCount); }
	short AddBoolItem(long lMsgId, short * pValue, long lCount) { return EZGEM_AddBoolItem(pGEM, lMsgId, pValue, lCount); }
	short AddI1Item(long lMsgId, short * pValue, long lCount) { return EZGEM_AddI1Item(pGEM, lMsgId, pValue, lCount); }
	short AddI2Item(long lMsgId, short * pValue, long lCount) { return EZGEM_AddI2Item(pGEM, lMsgId, pValue, lCount); }
	short AddI4Item(long lMsgId, long * plValue, long lCount) { return EZGEM_AddI4Item(pGEM, lMsgId, plValue, lCount); }
	short AddI8Item(long lMsgId, long * plValue, long lCount) { return EZGEM_AddI8Item(pGEM, lMsgId, plValue, lCount); }
	short AddI8ItemI64(long lMsgId, LONGLONG * plValue, long lCount) { return EZGEM_AddI8ItemI64(pGEM, lMsgId, plValue, lCount); }
	short AddU1Item(long lMsgId, short * pValue, long lCount) { return EZGEM_AddU1Item(pGEM, lMsgId, pValue, lCount); }
	short AddU2Item(long lMsgId, long * plValue, long lCount) { return EZGEM_AddU2Item(pGEM, lMsgId, plValue, lCount); }
	short AddU4Item(long lMsgId, double * prValue, long lCount) { return EZGEM_AddU4Item(pGEM, lMsgId, prValue, lCount); }
	short AddU8Item(long lMsgId, double * prValue, long lCount) { return EZGEM_AddU8Item(pGEM, lMsgId, prValue, lCount); }
	short AddU8ItemU64(long lMsgId, ULONGLONG * prValue, long lCount) { return EZGEM_AddU8ItemU64(pGEM, lMsgId, prValue, lCount); }
	short AddF4Item(long lMsgId, float * prValue, long lCount) { return EZGEM_AddF4Item(pGEM, lMsgId, prValue, lCount); }
	short AddF8Item(long lMsgId, double * prValue, long lCount) { return EZGEM_AddF8Item(pGEM, lMsgId, prValue, lCount); }
//	short AddJ8Item(long lMsgId, LPCTSTR pszValue, long lCount) { return EZGEM_AddJ8Item(pGEM, lMsgId, pszValue, lCount); }
	short GetListItemOpen(long lMsgId) { return EZGEM_GetListItemOpen(pGEM, lMsgId); }
	short GetListItemClose(long lMsgId) { return EZGEM_GetListItemClose(pGEM, lMsgId); }
	long  GetAsciiItem(long lMsgId, BSTR * pszValue) { return EZGEM_GetAsciiItem(pGEM, lMsgId, pszValue); }
	long  GetJ8Item(long lMsgId, BSTR * pszValue) { return EZGEM_GetJ8Item(pGEM, lMsgId, pszValue); }
	long  GetBinaryItem(long lMsgId, short * pnValue) { return EZGEM_GetBinaryItem(pGEM, lMsgId, pnValue); }
	long  GetBinaryItem(long lMsgId, BYTE * pnValue) { return EZGEM_GetByteItem(pGEM, lMsgId, pnValue); }
	long  GetBoolItem(long lMsgId, short * pnValue) { return EZGEM_GetBoolItem(pGEM, lMsgId, pnValue); }
	long  GetI1Item(long lMsgId, short * pnValue) { return EZGEM_GetI1Item(pGEM, lMsgId, pnValue); }
	long  GetI2Item(long lMsgId, short * pnValue) { return EZGEM_GetI2Item(pGEM, lMsgId, pnValue); }
	long  GetI4Item(long lMsgId, long * plValue) { return EZGEM_GetI4Item(pGEM, lMsgId, plValue); }
	long  GetI8Item(long lMsgId, long * plValue) { return EZGEM_GetI8Item(pGEM, lMsgId, plValue); }
	long  GetI8ItemI64(long lMsgId, LONGLONG * plValue) { return EZGEM_GetI8ItemI64(pGEM, lMsgId, plValue); }
	long  GetU1Item(long lMsgId, short * pnValue) { return EZGEM_GetU1Item(pGEM, lMsgId, pnValue); }
	long  GetU2Item(long lMsgId, long * plValue) { return EZGEM_GetU2Item(pGEM, lMsgId, plValue); }
	long  GetU4Item(long lMsgId, double * prValue) { return EZGEM_GetU4Item(pGEM, lMsgId, prValue); }
	long  GetU8Item(long lMsgId, double * prValue) { return EZGEM_GetU8Item(pGEM, lMsgId, prValue); }
	long  GetU8ItemU64(long lMsgId, ULONGLONG * prValue) { return EZGEM_GetU8ItemU64(pGEM, lMsgId, prValue); }
	long  GetF4Item(long lMsgId, float * prValue) { return EZGEM_GetF4Item(pGEM, lMsgId, prValue); }
	long  GetF8Item(long lMsgId, double * prValue) { return EZGEM_GetF8Item(pGEM, lMsgId, prValue); }
//	void  SetLogFile(LPCTSTR strFileName, short bLogSecsII) { EZGEM_SetLogFile(pGEM, strFileName, bLogSecsII); }
	long  GetCurLogFile(BSTR *psCurLogFile) { return EZGEM_GetCurLogFile(pGEM, psCurLogFile); }
	short GetNextItemFormat(long lMsgId) { return EZGEM_GetNextItemFormat(pGEM, lMsgId); }
	short GetSubItemFormat(long lMsgId) { return EZGEM_GetSubItemFormat(pGEM, lMsgId); }
	long  GetNextItemCount(long lMsgId) { return EZGEM_GetNextItemCount(pGEM, lMsgId); }
	long  GetSubItemCount(long lMsgId) { return EZGEM_GetSubItemCount(pGEM, lMsgId); }
	short AbortMsg(long lMsgId) { return EZGEM_AbortMsg(pGEM, lMsgId); }
	void  SetLogRetention(short nDays) { EZGEM_SetLogRetention(pGEM, nDays); }
	short GetLogRetention() { return EZGEM_GetLogRetention(pGEM); }
	void  SetFormatCheck(short bEnabled) { EZGEM_SetFormatCheck(pGEM, bEnabled); }
	short GetFormatCheck() { return EZGEM_GetFormatCheck(pGEM); }
//	void  SetFormatFile(LPCTSTR lpszFormatFile) { EZGEM_SetFormatFile(pGEM, lpszFormatFile); }
//	long  AddFileBinaryItem(long lMsgId, LPCTSTR szFile) { return EZGEM_AddFileBinaryItem(pGEM, lMsgId, szFile); }
//	long  GetFileBinaryItem(long lMsgId, LPCTSTR szFile) { return EZGEM_GetFileBinaryItem(pGEM, lMsgId, szFile); }
	long  GetMsgHead(long lMsgId, UCHAR *pnByteBuff) { return EZGEM_GetMsgHead(pGEM, lMsgId, pnByteBuff); }
	long  GetMsgBody(long lMsgId, UCHAR *pnByteBuff, long lSize) { return EZGEM_GetMsgBody(pGEM, lMsgId, pnByteBuff, lSize); }
	void  EnableErrorMessage() { EZGEM_EnableErrorMessage(pGEM); }
	void  DisableErrorMessage() { EZGEM_DisableErrorMessage(pGEM); }
	short AddListItem(long lMsgId, long lCount) { return EZGEM_AddListItem(pGEM, lMsgId, lCount); }
	long  GetListItem(long lMsgId) { return EZGEM_GetListItem(pGEM, lMsgId); }
//	void   SetConfigFile(LPCTSTR strConfigFile) { EZGEM_SetConfigFile(pGEM, strConfigFile); }
//	void   SaveConfigFile(LPCTSTR strConfigFile) { EZGEM_SaveConfigFile(pGEM, strConfigFile); }
//	short  SeparateLog(LPCTSTR szLogFileName, short nStream, short nFunction) { return EZGEM_SeparateLog(pGEM, szLogFileName, nStream, nFunction); }
	void  SetMaxLogFileSize(short nMegaByte) { EZGEM_SetMaxLogFileSize(pGEM, nMegaByte); }
	short SetLogDelTime(long nDelTime) { return EZGEM_SetLogDelTime(pGEM, nDelTime); }
	long  SetMsgHead(long lMsgId, UCHAR* pnBuff) { return EZGEM_SetMsgHead(pGEM, lMsgId, pnBuff); }
	long  SetMsgBody(long lMsgId, UCHAR* pnBuff, long lSize) { return EZGEM_SetMsgBody(pGEM, lMsgId, pnBuff, lSize); }
//	long  AddArrayItem(long lMsgId, LPCTSTR pszType, long nDataCount, LPCTSTR pszData) { return EZGEM_AddArrayItem(pGEM, lMsgId, pszType, nDataCount, pszData); }
	long  GetArrayItem(long lMsgId, BSTR * pszValue) { return EZGEM_GetArrayItem(pGEM, lMsgId, pszValue); }
	void  EnableLog() { EZGEM_EnableLog(pGEM); }
	void  DisableLog() { EZGEM_DisableLog(pGEM); }
	void  SkipLog(short nStream, short nFunction) { EZGEM_SkipLog(pGEM, nStream, nFunction); }
	void  SkipLogReset(short nStream, short nFunction) { EZGEM_SkipLogReset(pGEM, nStream, nFunction); }
//	void  WriteUserLog(LPCTSTR pszLog) { EZGEM_WriteUserLog(pGEM, pszLog); }
	long  GetNextEvent(short  *pnEventID, long  *plParam) { return EZGEM_GetNextEvent(pGEM, pnEventID, plParam); }
	long  GetNextMsg(long  *plMsgId) { return EZGEM_GetNextMsg(pGEM, plMsgId); }
	short GetMsgQueSize() { return EZGEM_GetMsgQueSize(pGEM); }
	long  GetSysByte(long lMsgId) { return EZGEM_GetSysByte(pGEM, lMsgId); }
	long  GetSysByteEx(long nTransactionID) { return EZGEM_GetSysByteEx(pGEM, nTransactionID); }
	long  GetItem(long lMsgId, BSTR *pstrValue) { return EZGEM_GetItem(pGEM, lMsgId, pstrValue); }
//	long  SaveMsgToFile(long lMsgId, LPCTSTR sFile) { return EZGEM_SaveMsgToFile(pGEM, lMsgId, sFile); }
//	long  SendMsgFromFile(LPCTSTR sFile) { return EZGEM_SendMsgFromFile(pGEM, sFile); }
//	long  GetListChildItem(long lMsgId, LPCTSTR sDelimiter, BSTR *psValue, long *plLength)	{ return EZGEM_GetListChildItem(pGEM, lMsgId, sDelimiter, psValue,  plLength); }
//	long  GetNameValueListItem(long lMsgId, LPCTSTR sDelimiter, BSTR* psNameList, BSTR* psValueList, long* plCount) { return EZGEM_GetNameValueListItem(pGEM, lMsgId, sDelimiter, psNameList, psValueList, plCount); }
	long  SendS9F3(long lMsgId) { return EZGEM_SendS9F3(pGEM, lMsgId); }
	long  SendS9F5(long lMsgId) { return EZGEM_SendS9F5(pGEM, lMsgId); }
	long  SendS9F7(long lMsgId) { return EZGEM_SendS9F7(pGEM, lMsgId); }
	long  SendS9F11(long lMsgId) { return EZGEM_SendS9F11(pGEM, lMsgId); }
	void  GetVersionInfo(BSTR *psVersionInfo) { EZGEM_GetVersionInfo(pGEM, psVersionInfo); }
//	long  GetItemInfo(long lMsgId, LPCTSTR sPos, short *pnFormat, long *plCount) 	{ 		return EZGEM_GetItemInfo(pGEM, lMsgId, sPos, pnFormat, plCount); 	}
	//---------------------- END OF EZNET FUNCTION ---------------------------

	void  SetEstablishCommTimer(short nCommReqTimeOut) { EZGEM_SetCommRequestTime(pGEM, nCommReqTimeOut); }
	short GetEstablishCommTimer() { return EZGEM_GetCommRequestTime(pGEM); }
//	void  SetModelName(const char *lpszModelName) { EZGEM_SetModelName(pGEM, lpszModelName); }
//	void  SetSoftRev(const char *lpszSoftRev) { EZGEM_SetSoftRev(pGEM, lpszSoftRev); }
	void  GoOffline() { EZGEM_GoOffline(pGEM); }
	void  GoOnlineLocal() { EZGEM_GoOnlineLocal(pGEM); }
	void  GoOnlineRemote() { EZGEM_GoOnlineRemote(pGEM); }
//	long  AddCEID(long CEID, const char *pszName, const char *pszDescription) { return EZGEM_AddCEID(pGEM, CEID, pszName, pszDescription); }
//	long  AddSVID(long SVID, const char *pszName, const char *pszFormat, const char *pszUnit) { return EZGEM_AddSVID(pGEM, SVID, pszName, pszFormat, pszUnit); }
//	long  AddDVID(long DVID, const char *pszName, const char *pszFormat) { return EZGEM_AddDVID(pGEM, DVID, pszName, pszFormat); }
//	long  AddALID(long ALID, const char *pszName, const char *pszALCD) { return EZGEM_AddALID(pGEM, ALID, pszName, pszALCD); }
//	long  AddECID(long ECID, const char *pszName, const char *pszUnit, const char *pszFormat) { return EZGEM_AddECID(pGEM, ECID, pszName, pszUnit, pszFormat); }
//	long  AddRemoteCommand(const char *pszCommand) { return EZGEM_AddRemoteCommand(pGEM, pszCommand); }
	short GetRemoteCommand(long lMsgId, BSTR  *pstrCommandName) { return EZGEM_GetRemoteCommand(pGEM, lMsgId, pstrCommandName); }
	short GetRemoteCommand(long lMsgId, CString* strCommandName)
	{
		BSTR bstrCommandName = nullptr;
		short nResult = EZGEM_GetRemoteCommand(pGEM, lMsgId, &bstrCommandName);
		if (SUCCEEDED(nResult))
		{
			*strCommandName = CString(bstrCommandName);
			::SysFreeString(bstrCommandName);
		}
		return nResult;
	}
	short GetRemoteCommand(long lMsgId, CString& strCommandName)
	{
		BSTR bstrCommandName = nullptr;
		short nResult = EZGEM_GetRemoteCommand(pGEM, lMsgId, &bstrCommandName);
		if (SUCCEEDED(nResult))
		{
			strCommandName = CString(bstrCommandName);
			::SysFreeString(bstrCommandName);
		}
		else
		{
			strCommandName.Empty();
		}
		return nResult;
	}
	short GetRemoteCommandParam(long lMsgId, short nIndex, BSTR  *pstrName, BSTR  *pstrValue, short *pnFormat) { return EZGEM_GetRemoteCommandParam(pGEM, lMsgId, nIndex, pstrName, pstrValue, pnFormat); }
	short GetRemoteCommandParam(long lMsgId, short nIndex, CString* strName, CString* strValue, short* pnFormat)
	{
		BSTR pstrName = 0;
		BSTR pstrValue = 0;
		short nAck = EZGEM_GetRemoteCommandParam(pGEM, lMsgId, nIndex, &pstrName, &pstrValue, pnFormat);
		if (nAck < 0) return nAck;
		*strName = (CString)pstrName;
		*strValue = (CString)pstrValue;

		SysFreeString(pstrName);
		SysFreeString(pstrValue);

		return  nAck;
	}
	short GetRemoteCommandParam(long lMsgId, short nIndex, CString& strName, CString& strValue, short* pnFormat)
	{
		BSTR bstrName = nullptr;
		BSTR bstrValue = nullptr;
		short nResult = EZGEM_GetRemoteCommandParam(pGEM, lMsgId, nIndex, &bstrName, &bstrValue, pnFormat);
		if (SUCCEEDED(nResult))
		{
			if (bstrName)
			{
				strName = CString(bstrName);
				::SysFreeString(bstrName);
			}
			else
			{
				strName.Empty();
			}
			if (bstrValue)
			{
				strValue = CString(bstrValue);
				::SysFreeString(bstrValue);
			}
			else
			{
				strValue.Empty();
			}
		}
		else
		{
			strName.Empty();
			strValue.Empty();
		}
		return nResult;
	}
	short ReplyRemoteCommand(long lMsgId, short HCACK) { return EZGEM_ReplyRemoteCommand(pGEM, lMsgId, HCACK); }
	short SendEventReport(long CEID) { return EZGEM_SendEventReport(pGEM, CEID); }
	short SendEventReportEx(long CEID, long nTransactionID) { return EZGEM_SendEventReportEx(pGEM, CEID, nTransactionID); }
	short SendAlarmReport(long ALID, short ALCD) { return EZGEM_SendAlarmReport(pGEM, ALID, ALCD); }
	short SendAlarmReportEx(long ALID, short ALCD, short nMode) { return EZGEM_SendAlarmReportEx(pGEM, ALID, ALCD, nMode); }
	long  DisableAutoReply(short nStream, short nFunction) { return EZGEM_DisableAutoReply(pGEM, nStream, nFunction); }
	long  EnableAutoReply(short nStream, short nFunction) { return EZGEM_EnableAutoReply(pGEM, nStream, nFunction); }
//	long  SetSVIDValue(long SVID, const char *pszValue) { return EZGEM_SetSVIDValue(pGEM, SVID, pszValue); }
//	long  SetVIDValue(long VID, const char *pszValue) { return EZGEM_SetVIDValue(pGEM, VID, pszValue); }
	short GetSVIDValue(long SVID, BSTR  *pstrCurrentValue) { return EZGEM_GetSVIDValue(pGEM, SVID, pstrCurrentValue); }
	long  GetSVID(long SVID, short  *pnFormat, BSTR  *pstrName) { return EZGEM_GetSVID(pGEM, SVID, pnFormat, pstrName); }
	short GetHostSetECID(long lMsgId, long *lpECID, BSTR *pstrNewValue) { return EZGEM_GetHostSetECID(pGEM, lMsgId, lpECID, pstrNewValue); }
	short GetHostSetECID(long lMsgId, long* lpECID, CString* strNewValue)
	{
		short nAck = 0;
		BSTR bstNewValue = 0;
		nAck = EZGEM_GetHostSetECID(pGEM, lMsgId, lpECID, &bstNewValue);
		if (nAck < 0) return nAck;
		*strNewValue = (CString)bstNewValue;
		SysFreeString(bstNewValue);
		return nAck;
	}
	short GetHostSetECID(long lMsgId, long* lpECID, CString& strNewValue)
	{
		BSTR bstrNewValue = nullptr;
		short nResult = EZGEM_GetHostSetECID(pGEM, lMsgId, lpECID, &bstrNewValue);
		if (nResult < 0) return nResult;
		strNewValue = CString(bstrNewValue);
		::SysFreeString(bstrNewValue);
		return nResult;
	}
//	short SetECValue(long ECID, const char *pszValue) { return EZGEM_SetECValue(pGEM, ECID, pszValue); }
	long  GetECValue(long ECID, BSTR  *pstrValue) { return EZGEM_GetECValue(pGEM, ECID, pstrValue); }
//	short SetECRange(long ECID, const char *pszMinValue, const char *pszMaxValue) { return EZGEM_SetECRange(pGEM, ECID, pszMinValue, pszMaxValue); }
	short ReplyHostSetECID(long lMsgId, short EAC) { return EZGEM_ReplyHostSetECID(pGEM, lMsgId, EAC); }
	void  EnableSpooling() { EZGEM_EnableSpooling(pGEM); }
	void  DisableSpooling() { EZGEM_DisableSpooling(pGEM); }
	long  GetSpoolCount() { return EZGEM_GetSpoolCount(pGEM); }
	void  SetMaxSpoolCount(UINT nMaxSpoolCount) { EZGEM_SetMaxSpoolCount(pGEM, nMaxSpoolCount); }
	long  GetMaxSpoolCount() { return EZGEM_GetMaxSpoolCount(pGEM); }
	void  SetMaxSpoolTransmitCount(UINT nMaxSpoolTransmit) { EZGEM_SetMaxSpoolTransmitCount(pGEM, nMaxSpoolTransmit); }
	long  GetMaxSpoolTransmitCount() { return EZGEM_GetMaxSpoolTransmitCount(pGEM); }
	void  EnableSpoolOverwrite() { EZGEM_EnableSpoolOverwrite(pGEM); }
	void  DisableSpoolOverwrite() { EZGEM_DisableSpoolOverwrite(pGEM); }
	long  GetTerminalMsg(long lMsgId, short *pnTID, BSTR *pstrMsg) { return EZGEM_GetTerminalMsg(pGEM, lMsgId, pnTID, pstrMsg); }
	long  GetTerminalMsg(long lMsgId, short* pnTID, CString* strMsg)
	{
		long lAck = 0;
		BSTR bstMsg = 0;
		lAck = EZGEM_GetTerminalMsg(pGEM, lMsgId, pnTID, &bstMsg);
		if (lAck < 0) return lAck;
		*strMsg = (CString)bstMsg;
		SysFreeString(bstMsg);
		return lAck;
	}
	long  GetTerminalMsg(long lMsgId, short* pnTID, CString& strMsg)
	{
		BSTR bstrMsg = nullptr;
		long nResult = EZGEM_GetTerminalMsg(pGEM, lMsgId, pnTID, &bstrMsg);
		if (nResult < 0) return nResult;
		strMsg = CString(bstrMsg);
		::SysFreeString(bstrMsg);
		return nResult;
	}
//	void  SetReportFilePath(const char *pszFilePath) { EZGEM_SetReportFilePath(pGEM, pszFilePath); }
	long  AddStatusValueToMsg(long lMsgId, long SVID) { return EZGEM_AddStatusValueToMsg(pGEM, lMsgId, SVID); }
	long  SetTimeFormat(short nTimeFormat) { return EZGEM_SetTimeFormat(pGEM, nTimeFormat); }
//	short SetFormatCode(const char *szItemName, const char *szFormatCode) { return EZGEM_SetFormatCode(pGEM, szItemName, szFormatCode); }
	void  GetSpoolTime(BSTR  *pstrStartTime, BSTR  *pstrFullTime) { EZGEM_GetSpoolTime(pGEM, pstrStartTime, pstrFullTime); }
	void  GetSpoolTime(CString* pStrStartTime, CString* pStrFullTime)
	{
		BSTR bstrStartTime = nullptr;
		BSTR bstrFullTime = nullptr;
		EZGEM_GetSpoolTime(pGEM, &bstrStartTime, &bstrFullTime);

		if (bstrStartTime != nullptr)
		{
			if (pStrStartTime) *pStrStartTime = CString(bstrStartTime);
			::SysFreeString(bstrStartTime);
		}
		else
		{
			if (pStrStartTime) pStrStartTime->Empty();
		}
		if (bstrFullTime != nullptr)
		{
			if (pStrFullTime) *pStrFullTime = CString(bstrFullTime);
			::SysFreeString(bstrFullTime);
		}
		else
		{
			if (pStrFullTime) pStrFullTime->Empty();
		}
	}
	void  GetSpoolTime(CString& strStartTime, CString& strFullTime)
	{
		BSTR bstrStartTime = nullptr;
		BSTR bstrFullTime = nullptr;
		EZGEM_GetSpoolTime(pGEM, &bstrStartTime, &bstrFullTime);
		if (bstrStartTime != nullptr)
		{
			strStartTime = CString(bstrStartTime);
			::SysFreeString(bstrStartTime);
		}
		else
		{
			strStartTime.Empty();
		}
		if (bstrFullTime != nullptr)
		{
			strFullTime = CString(bstrFullTime);
			::SysFreeString(bstrFullTime);
		}
		else
		{
			strFullTime.Empty();
		}
	}
	long  GetAlarmInfo(long ALID, short  *pnALCD, BSTR  *pstrText) { return EZGEM_GetAlarmInfo(pGEM, ALID, pnALCD, pstrText); }
	BSTR  GetAlarmText(long ALID) { return EZGEM_GetAlarmText(pGEM, ALID); }
	short GetAlarmCode(long ALID) { return EZGEM_GetAlarmCode(pGEM, ALID); }
	long  GetAlarmState(long ALID) { return EZGEM_GetAlarmState(pGEM, ALID); }
//	void  SetRemoteCommandErrorCode(long lMsgId, LPCTSTR szCommand, short nParamIndex, short nErrorCode) { EZGEM_SetRemoteCommandErrorCode(pGEM, lMsgId, szCommand, nParamIndex, nErrorCode); }
	long  ResetMsgReceived(long lMsgId) { return EZGEM_ResetMsgReceived(pGEM, lMsgId); }
	long  WriteEZGemStatus() { return EZGEM_WriteEZGemStatus(pGEM); }
	long  GetReport(long RPTID, long *plSVID) { return EZGEM_GetReport(pGEM, RPTID, plSVID);}
	long  GetEventReport(long CEID, long *plRPTID) { return EZGEM_GetEventReport(pGEM, CEID, plRPTID); }
	long  GetTraceInfo(long TRID, long *plSampleCount, long *plVidCount, BSTR *pstrVidList, BSTR *pstrPeriod){ return EZGEM_GetTraceInfo(pGEM, TRID, plSampleCount, plVidCount, pstrVidList, pstrPeriod);}
	//----------------------------------------------------------------------------
	//	GEM300 API
	//  CMS
//	long SetLoadPort(int nPortID, int nTransferState, int nAccessMode, LPCTSTR strLocationName, LPCTSTR strCarrierID) { return EZGEM_SetLoadPort(pGEM, nPortID, nTransferState, nAccessMode, strLocationName, strCarrierID); }
	long SetTransferState(int nPortID, int nTransferState) { return EZGEM_SetTransferState(pGEM, nPortID, nTransferState); }
	long SetCarrierArrived(int nPortID) { return EZGEM_SetCarrierArrived(pGEM, nPortID); }
	long SetCarrierRemoved(int nPortID) { return EZGEM_SetCarrierRemoved(pGEM, nPortID); }
	long SetDoorState(int nPortID, int nState) { return EZGEM_SetDoorState(pGEM, nPortID, nState); }
	long SetDockState(int nPortID, int nState) { return EZGEM_SetDockState(pGEM, nPortID, nState); }
	long SetClampState(int nPortID, int nState) { return EZGEM_SetClampState(pGEM, nPortID, nState); }
	long SetLoadPortAccessMode(int nPortID, int nMode) { return EZGEM_SetLoadPortAccessMode(pGEM, nPortID, nMode); }
//	long SetCarrierAccessState(int nPortID, int nState, LPCTSTR strCarrierID) { return EZGEM_SetCarrierAccessState(pGEM, nPortID, nState, strCarrierID); }
//	long SetCarrierIDRead(int nPortID, LPCTSTR strCarrierID, int nResult) { return EZGEM_SetCarrierIDRead(pGEM, nPortID, strCarrierID, nResult); }
//	long SetCarrierIDStatus(int nPortID, LPCTSTR strCarrierID, int nStatus) { return EZGEM_SetCarrierIDStatus(pGEM, nPortID, strCarrierID, nStatus); }
//	long SetSlotMapRead(int nPortID, LPCTSTR strCarrierID, LPCTSTR strSlotMap, int nResult) { return EZGEM_SetSlotMapRead(pGEM, nPortID, strCarrierID, strSlotMap, nResult); }
//	long SetSlotMapStatus(int nPortID, LPCTSTR strCarrierID, int nStatus) { return EZGEM_SetSlotMapStatus(pGEM, nPortID, strCarrierID, nStatus); }
	long GetCarrierActionInfo(long lMsgId, int *pnPortID, BSTR *pstrCarrierID, int *pnContentMapCount, int *pnSlotMapCount) { return EZGEM_GetCarrierActionInfo(pGEM, lMsgId, pnPortID, pstrCarrierID, pnContentMapCount, pnSlotMapCount); }
	long GetCarrierActionInfo(long lMsgId, int* pnPortID, CString* pstrCarrierID, int* pnContentMapCount, int* pnSlotMapCount)
	{
		BSTR bstrCarrierID = nullptr;
		long nResult = EZGEM_GetCarrierActionInfo(pGEM, lMsgId, pnPortID, &bstrCarrierID, pnContentMapCount, pnSlotMapCount);
		if (nResult < 0) return nResult;
		*pstrCarrierID = CString(bstrCarrierID);
		SysFreeString(bstrCarrierID);
		return nResult;
	}
	long GetCarrierActionInfo(long lMsgId, int* pnPortID, CString& strCarrierID, int* pnContentMapCount, int* pnSlotMapCount)
	{
		BSTR bstrCarrierID = nullptr;
		long nResult = EZGEM_GetCarrierActionInfo(pGEM, lMsgId, pnPortID, &bstrCarrierID, pnContentMapCount, pnSlotMapCount);
		if (nResult < 0) return nResult;
		strCarrierID = CString(bstrCarrierID);
		SysFreeString(bstrCarrierID);
		return nResult;
	}
	long GetContentMapInfo(long lMsgId, int nIndex, BSTR *pstrContentMap) { return EZGEM_GetContentMapInfo(pGEM, lMsgId, nIndex, pstrContentMap); }
	long GetContentMapInfo(long lMsgId, int nIndex, CString* pstrContentMap)
	{
		BSTR bstrContentMap = nullptr;
		long nResult = EZGEM_GetContentMapInfo(pGEM, lMsgId, nIndex, &bstrContentMap);
		if (nResult < 0) return nResult;
		*pstrContentMap = CString(bstrContentMap);
		SysFreeString(bstrContentMap);
		return nResult;
	}
	long GetContentMapInfo(long lMsgId, int nIndex, CString& strContentMap)
	{
		BSTR bstrContentMap = nullptr;
		long nResult = EZGEM_GetContentMapInfo(pGEM, lMsgId, nIndex, &bstrContentMap);
		if (nResult < 0) return nResult;
		strContentMap = CString(bstrContentMap);
		SysFreeString(bstrContentMap);
		return nResult;
	}
	long GetSlotMapInfo(long lMsgId, BSTR *pstrSlotMap) { return EZGEM_GetSlotMapInfo(pGEM, lMsgId, pstrSlotMap); }
	long GetSlotMapInfo(long lMsgId, CString* pstrSlotMap)
	{
		BSTR bstrSlotMap = nullptr;
		long nResult = EZGEM_GetSlotMapInfo(pGEM, lMsgId, &bstrSlotMap);
		if (nResult < 0) return nResult;
		*pstrSlotMap = CString(bstrSlotMap);
		SysFreeString(bstrSlotMap);
		return nResult;
	}
	long GetSlotMapInfo(long lMsgId, CString& strSlotMap)
	{
		BSTR bstrSlotMap = nullptr;
		long nResult = EZGEM_GetSlotMapInfo(pGEM, lMsgId, &bstrSlotMap);
		if (nResult < 0) return nResult;
		strSlotMap = CString(bstrSlotMap);
		SysFreeString(bstrSlotMap);
		return nResult;
	}
	long GetHostSetLoadPortAccessMode(long lMsgId, int *pnAccessMode, BSTR *pstrPortList) { return EZGEM_GetHostSetLoadPortAccessMode(pGEM,lMsgId,pnAccessMode,pstrPortList); }
	long GetHostSetLoadPortAccessMode(long lMsgId, int* pnAccessMode, CString* pstrPortList)
	{
		BSTR bstrPortList = nullptr;
		long nResult = EZGEM_GetHostSetLoadPortAccessMode(pGEM, lMsgId, pnAccessMode, &bstrPortList);
		if (nResult < 0) return nResult;
		*pstrPortList = CString(bstrPortList);
		SysFreeString(bstrPortList);
		return nResult;
	}
	long GetHostSetLoadPortAccessMode(long lMsgId, int* pnAccessMode, CString& strPortList)
	{
		BSTR bstrPortList = nullptr;
		long nResult = EZGEM_GetHostSetLoadPortAccessMode(pGEM, lMsgId, pnAccessMode, &bstrPortList);
		if (nResult < 0) return nResult;
		strPortList = CString(bstrPortList);
		SysFreeString(bstrPortList);
		return nResult;
	}
	long GetHostSetLoadPortServiceMode(long lMsgId, int *pnServiceMode, BSTR *pstrPortList) { return EZGEM_GetHostSetLoadPortServiceMode(pGEM,lMsgId,pnServiceMode,pstrPortList); }
	long GetHostSetLoadPortServiceMode(long lMsgId, int* pnServiceMode, CString* pstrPortList)
	{
		BSTR bstrPortList = nullptr;
		long nResult = EZGEM_GetHostSetLoadPortServiceMode(pGEM, lMsgId, pnServiceMode, &bstrPortList);
		if (nResult < 0) return nResult;
		*pstrPortList = CString(bstrPortList);
		SysFreeString(bstrPortList);
		return nResult;
	}
	long GetHostSetLoadPortServiceMode(long lMsgId, int* pnServiceMode, CString& strPortList)
	{
		BSTR bstrPortList = nullptr;
		long nResult = EZGEM_GetHostSetLoadPortServiceMode(pGEM, lMsgId, pnServiceMode, &bstrPortList);
		if (nResult < 0) return nResult;
		strPortList = CString(bstrPortList);
		SysFreeString(bstrPortList);
		return nResult;
	}

	long ReplyCarrierAction(long lMsgId, int CAACK) { return EZGEM_ReplyCarrierAction(pGEM, lMsgId, CAACK); }
//	long SetCarrierActionErrorCode(long lMsgId, int nErrorCode, LPCTSTR strErrorText) { return EZGEM_SetCarrierActionErrorCode(pGEM, lMsgId, nErrorCode, strErrorText); }
//	long DeleteCarrier(LPCTSTR sCarrierID) { return EZGEM_DeleteCarrier(pGEM, sCarrierID); }
	long DeleteAllCarrier() { return EZGEM_DeleteAllCarrier(pGEM); }
	long GetCarrierCount(){	return EZGEM_GetCarrierCount(pGEM);}
	long GetCarrierLocCount(){return EZGEM_GetCarrierLocCount(pGEM);}
	long SetCarrierInternalBufferMode(int nMode){	return EZGEM_SetCarrierInternalBufferMode(pGEM,nMode);}

	// PJM
	long GetHostSetPrJobCount(long lMsgId) { return EZGEM_GetHostSetPrJobCount(pGEM, lMsgId); }
	long GetHostSetPrJob(long lMsgId, int nIndex, BSTR *pstrPrJobID, BSTR *pstrPPID, int *pnCarrierCount, int *pnAutoStart, int *pnParamCount)	{		return EZGEM_GetHostSetPrJob(pGEM, lMsgId, nIndex, pstrPrJobID, pstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);	}
	long GetHostSetPrJob(long lMsgId, int nIndex, CString* pstrPrJobID, CString* pstrPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
		BSTR bstrPrJobID = nullptr;
		BSTR bstrPPID = nullptr;
		long nResult = EZGEM_GetHostSetPrJob(pGEM, lMsgId, nIndex, &bstrPrJobID, &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		if (nResult < 0) return nResult;
		if (pstrPrJobID)
		{
			if (bstrPrJobID)
			{
				*pstrPrJobID = CString(bstrPrJobID);
				SysFreeString(bstrPrJobID);
			}
			else
			{
				pstrPrJobID->Empty();
			}
		}
		if (pstrPPID)
		{
			if (bstrPPID)
			{
				*pstrPPID = CString(bstrPPID);
				SysFreeString(bstrPPID);
			}
			else
			{
				pstrPPID->Empty();
			}
		}
		return nResult;
	}
	long GetHostSetPrJob(long lMsgId, int nIndex, CString& strPrJobID, CString& strPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
		BSTR bstrPrJobID = nullptr;
		BSTR bstrPPID = nullptr;
		long nResult = EZGEM_GetHostSetPrJob(pGEM, lMsgId, nIndex, &bstrPrJobID, &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		if (nResult < 0) return nResult;
		if (bstrPrJobID)
		{
			strPrJobID = CString(bstrPrJobID);
			SysFreeString(bstrPrJobID);
		}
		else
		{
			strPrJobID.Empty();
		}
		if (bstrPPID)
		{
			strPPID = CString(bstrPPID);
			SysFreeString(bstrPPID);
		}
		else
		{
			strPPID.Empty();
		}
		return nResult;
	}
	long GetHostSetPrJobStartMethod(long lMsgId, int *pnPrJobCount, BSTR *pstrPrJobList, int *pnStartMethod)	{		return EZGEM_GetHostSetPrJobStartMethod(pGEM,lMsgId,pnPrJobCount,pstrPrJobList,pnStartMethod);	}
	long GetHostSetPrJobStartMethod(long lMsgId, int* pnPrJobCount, CString* pstrPrJobList, int* pnStartMethod)
	{
		BSTR bstrPrJobList = nullptr;
		long lRet = EZGEM_GetHostSetPrJobStartMethod(pGEM, lMsgId, pnPrJobCount, &bstrPrJobList, pnStartMethod);
		if (SUCCEEDED(lRet) && bstrPrJobList != nullptr)
		{
			*pstrPrJobList = CString(bstrPrJobList);
			::SysFreeString(bstrPrJobList);
		}
		else
		{
			pstrPrJobList->Empty();
		}
		return lRet;
	}
	long GetHostSetPrJobStartMethod(long lMsgId, int* pnPrJobCount, CString& strPrJobList, int* pnStartMethod)
	{
		BSTR bstrPrJobList = nullptr;
		long lRet = EZGEM_GetHostSetPrJobStartMethod(pGEM, lMsgId, pnPrJobCount, &bstrPrJobList, pnStartMethod);
		if (SUCCEEDED(lRet) && bstrPrJobList != nullptr)
		{
			strPrJobList = CString(bstrPrJobList);
			::SysFreeString(bstrPrJobList);
		}
		else
		{
			strPrJobList.Empty();
		}
		return lRet;
	}
	long GetHostSetPrJobParam(long lMsgId, BSTR *pstrPrJob, int *pnParamCount){		return EZGEM_GetHostSetPrJobParam(pGEM, lMsgId, pstrPrJob, pnParamCount);	}
	long GetHostSetPrJobParam(long lMsgId, CString* pstrPrJob, int* pnParamCount)
	{
		BSTR bstrPrJob = nullptr;
		long nResult = EZGEM_GetHostSetPrJobParam(pGEM, lMsgId, &bstrPrJob, pnParamCount);
		if (nResult < 0) return nResult;
		if (pstrPrJob)
		{
			if (bstrPrJob)
			{
				*pstrPrJob = CString(bstrPrJob);
				SysFreeString(bstrPrJob);
			}
			else
			{
				pstrPrJob->Empty();
			}
		}
		return nResult;
	}
	long GetHostSetPrJobParam(long lMsgId, CString& strPrJob, int* pnParamCount)
	{
		BSTR bstrPrJob = nullptr;
		long nResult = EZGEM_GetHostSetPrJobParam(pGEM, lMsgId, &bstrPrJob, pnParamCount);
		if (nResult < 0) return nResult;
		if (bstrPrJob)
		{
			strPrJob = CString(bstrPrJob);
			SysFreeString(bstrPrJob);
		}
		else
		{
			strPrJob.Empty();
		}
		return nResult;
	}

//	long GetPrJobCarrier(LPCTSTR szPrJobID, int nIndex, BSTR *pstrCarrierID, BSTR *pstrSlotList)	{		return EZGEM_GetPrJobCarrier(pGEM, szPrJobID, nIndex, pstrCarrierID, pstrSlotList);	}
//	long GetPrJobParam(LPCTSTR szPrJobID, int nIndex, BSTR *pstrParamName, BSTR *pstrParamVal) { 	return EZGEM_GetPrJobParam(pGEM, szPrJobID, nIndex, pstrParamName, pstrParamVal); 	}
//	long GetPrJobRecipeMethod(LPCTSTR szPrJobID, int *pnRecipeMethod) { return EZGEM_GetPrJobRecipeMethod(pGEM, szPrJobID, pnRecipeMethod); }
	long GetPrJobCommand(long lMsgId, BSTR *pstrPrJobID, BSTR *pstrCommand) { return EZGEM_GetPrJobCommand(pGEM, lMsgId, pstrPrJobID, pstrCommand); }
//	long SetPrJobErrorCode(long lMsgId, LPCTSTR szPrJobID, int nErrorCode, LPCTSTR szErrorText)	{	return EZGEM_SetPrJobErrorCode(pGEM, lMsgId, szPrJobID, nErrorCode, szErrorText);	}
	long ReplyHostSetPrJob(long lMsgId)	{	return EZGEM_ReplyHostSetPrJob(pGEM, lMsgId);}
	long ReplyPrJobCommand(long lMsgId) {	return EZGEM_ReplyPrJobCommand(pGEM, lMsgId);}
	long GetPrJobCommand(long lMsgId, CString* pstrPrJobID, CString* pstrCommand)
	{
		BSTR bstrPrJobID = nullptr;
		BSTR bstrCommand = nullptr;
		long nResult = EZGEM_GetPrJobCommand(pGEM, lMsgId, &bstrPrJobID, &bstrCommand);
		if (nResult < 0) return nResult;
		if (pstrPrJobID)
		{
			if (bstrPrJobID)
			{
				*pstrPrJobID = CString(bstrPrJobID);
				SysFreeString(bstrPrJobID);
			}
			else
			{
				pstrPrJobID->Empty();
			}
		}
		if (pstrCommand)
		{
			if (bstrCommand)
			{
				*pstrCommand = CString(bstrCommand);
				SysFreeString(bstrCommand);
			}
			else
			{
				pstrCommand->Empty();
			}
		}
		return nResult;
	}
	long GetPrJobCommand(long lMsgId, CString& strPrJobID, CString& strCommand)
	{
		BSTR bstrPrJobID = nullptr;
		BSTR bstrCommand = nullptr;
		long nResult = EZGEM_GetPrJobCommand(pGEM, lMsgId, &bstrPrJobID, &bstrCommand);
		if (nResult < 0) return nResult;
		if (bstrPrJobID)
		{
			strPrJobID = CString(bstrPrJobID);
			SysFreeString(bstrPrJobID);
		}
		else
		{
			strPrJobID.Empty();
		}
		if (bstrCommand)
		{
			strCommand = CString(bstrCommand);
			SysFreeString(bstrCommand);
		}
		else
		{
			strCommand.Empty();
		}
		return nResult;
	}
	long GetPrJobCount() { return EZGEM_GetPrJobCount(pGEM); }
	long GetPrJobSpace() { return EZGEM_GetPrJobSpace(pGEM); }
	long GetPrJob(long nIndex, BSTR *pstrPrJobID, BSTR *pstrPPID, int *pnCarrierCount, int *pnAutoStart, int *pnParamCount)	{	return EZGEM_GetPrJob(pGEM, nIndex, pstrPrJobID, pstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);	}
	long GetPrJob(long nIndex, CString* pstrPrJobID, CString* pstrPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
		BSTR bstrPrJobID = nullptr;
		BSTR bstrPPID = nullptr;
		long nResult = EZGEM_GetPrJob(pGEM, nIndex, &bstrPrJobID, &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		if (nResult < 0) return nResult;
		if (pstrPrJobID)
		{
			if (bstrPrJobID)
			{
				*pstrPrJobID = CString(bstrPrJobID);
				SysFreeString(bstrPrJobID);
			}
			else
			{
				pstrPrJobID->Empty();
			}
		}
		if (pstrPPID)
		{
			if (bstrPPID)
			{
				*pstrPPID = CString(bstrPPID);
				SysFreeString(bstrPPID);
			}
			else
			{
				pstrPPID->Empty();
			}
		}
		return nResult;
	}
	long GetPrJob(long nIndex, CString& strPrJobID, CString& strPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
		BSTR bstrPrJobID = nullptr;
		BSTR bstrPPID = nullptr;
		long nResult = EZGEM_GetPrJob(pGEM, nIndex, &bstrPrJobID, &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		if (nResult < 0) return nResult;
		if (bstrPrJobID)
		{
			strPrJobID = CString(bstrPrJobID);
			SysFreeString(bstrPrJobID);
		}
		else
		{
			strPrJobID.Empty();
		}
		if (bstrPPID)
		{
			strPPID = CString(bstrPPID);
			SysFreeString(bstrPPID);
		}
		else
		{
			strPPID.Empty();
		}
		return nResult;
	}
//	long GetPrJobInfo(LPCTSTR szPrJobID, BSTR *pstrPPID, int *pnCarrierCount, int *pnAutoStart, int *pnParamCount)	{	return EZGEM_GetPrJobInfo(pGEM, szPrJobID, pstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);	}
	long GetPrJobDeleted(BSTR *pstrPrJobID) { return EZGEM_GetPrJobDeleted(pGEM, pstrPrJobID); }
	long GetPrJobDeleted(CString* pstrPrJobID)
	{
		BSTR bstrPrJobID = nullptr;
		long nResult = EZGEM_GetPrJobDeleted(pGEM, &bstrPrJobID);
		if (nResult < 0) return nResult;
		if (pstrPrJobID)
		{
			if (bstrPrJobID)
			{
				*pstrPrJobID = CString(bstrPrJobID);
				SysFreeString(bstrPrJobID);
			}
			else
			{
				pstrPrJobID->Empty();
			}
		}
		return nResult;
	}
	long GetPrJobDeleted(CString& strPrJobID)
	{
		BSTR bstrPrJobID = nullptr;
		long nResult = EZGEM_GetPrJobDeleted(pGEM, &bstrPrJobID);
		if (nResult < 0) return nResult;
		if (bstrPrJobID)
		{
			strPrJobID = CString(bstrPrJobID);
			SysFreeString(bstrPrJobID);
		}
		else
		{
			strPrJobID.Empty();
		}
		return nResult;
	}

//	long DeletePrJob(LPCTSTR szPrJobID)	{	return EZGEM_DeletePrJob(pGEM, szPrJobID);	}
	long DeleteAllPrJob()	{	return EZGEM_DeleteAllPrJob(pGEM);	}
//	long GetPrJobState(LPCTSTR szPrJobID, int *pnPrJobState)	{ return EZGEM_GetPrJobState(pGEM, szPrJobID, pnPrJobState);	}
//	long SetPrJobState(LPCTSTR szPrJobID, int nPrJobState)	{	return EZGEM_SetPrJobState(pGEM, szPrJobID, nPrJobState);	}
//	long CreatePrJob(LPCTSTR sPrJobID, int nAutoStart, LPCTSTR sCarrierList, LPCTSTR sSlotList, LPCTSTR sPPID)	{		return EZGEM_CreatePrJob(pGEM, sPrJobID, nAutoStart, sCarrierList, sSlotList, sPPID);	}
//	long CreatePrJob(LPCTSTR sPrJobID, int nAutoStart, LPCTSTR sSubstrateList, LPCTSTR sPPID)	{		return EZGEM_CreatePrJobSubst(pGEM, sPrJobID, nAutoStart, sSubstrateList, sPPID);	}
//	long GetPrJobMaterialFormatCode(LPCTSTR sPrJobID) { return EZGEM_GetPrJobMaterialFormatCode(pGEM, sPrJobID); }
	long AddPrJobParam(LPCTSTR sPrJobID, LPCTSTR sParamName, LPCTSTR sParamVal) { return EZGEM_AddPrJobParam(pGEM,sPrJobID,sParamName,sParamVal); }
	// CJM
	long GetHostSetCtrlJob(long lMsgId, BSTR *pstrCtrlJobID, int *pnPrJobCount, int *pnAutoStart)	{	return EZGEM_GetHostSetCtrlJob(pGEM, lMsgId, pstrCtrlJobID, pnPrJobCount, pnAutoStart);	}
	long GetHostSetCtrlJob(long lMsgId, CString* pstrCtrlJobID, int* pnPrJobCount, int* pnAutoStart)
	{
		BSTR bstrCtrlJobID = nullptr;
		long lResult = EZGEM_GetHostSetCtrlJob(pGEM, lMsgId, &bstrCtrlJobID, pnPrJobCount, pnAutoStart);
		if (lResult < 0) return lResult;
		*pstrCtrlJobID = CString(bstrCtrlJobID);
		::SysFreeString(bstrCtrlJobID);
		return lResult;
	}
	long GetHostSetCtrlJob(long lMsgId, CString& strCtrlJobID, int* pnPrJobCount, int* pnAutoStart)
	{
		BSTR bstrCtrlJobID = nullptr;
		long lResult = EZGEM_GetHostSetCtrlJob(pGEM, lMsgId, &bstrCtrlJobID, pnPrJobCount, pnAutoStart);
		if (lResult < 0) return lResult;
		strCtrlJobID = CString(bstrCtrlJobID);
		::SysFreeString(bstrCtrlJobID);
		return lResult;
	}
	long GetCtrlJob(long nIndex, BSTR *pstrCtrlJobID, int *pnPrJobCount, int *pnAutoStart)	{	return EZGEM_GetCtrlJob(pGEM, nIndex, pstrCtrlJobID, pnPrJobCount, pnAutoStart);	}
	long GetCtrlJob(long nIndex, CString* pstrCtrlJobID, int* pnPrJobCount, int* pnAutoStart)
	{
		BSTR bstrCtrlJobID = nullptr;
		long lResult = EZGEM_GetCtrlJob(pGEM, nIndex, &bstrCtrlJobID, pnPrJobCount, pnAutoStart);
		if (lResult < 0) return lResult;
		*pstrCtrlJobID = CString(bstrCtrlJobID);
		::SysFreeString(bstrCtrlJobID);
		return lResult;
	}
	long GetCtrlJob(long nIndex, CString& strCtrlJobID, int* pnPrJobCount, int* pnAutoStart)
	{
		BSTR bstrCtrlJobID = nullptr;
		long lResult = EZGEM_GetCtrlJob(pGEM, nIndex, &bstrCtrlJobID, pnPrJobCount, pnAutoStart);
		if (lResult < 0) return lResult;
		strCtrlJobID = CString(bstrCtrlJobID);
		::SysFreeString(bstrCtrlJobID);
		return lResult;
	}
//	long GetCtrlJobInfo(LPCTSTR szCtrlJobID, int *pnPrJobCount, int *pnAutoStart)	{	return EZGEM_GetCtrlJobInfo(pGEM, szCtrlJobID, pnPrJobCount, pnAutoStart);	}
//	long GetCtrlJobMtrlOutMapCount(LPCTSTR szCtrlJobID, int *pnMtrlOutMapCount)	{		return EZGEM_GetCtrlJobMtrlOutMapCount(pGEM, szCtrlJobID, pnMtrlOutMapCount);	}
//	long GetCtrlJobMtrlOutInfo(LPCTSTR szCtrlJobID, int nMapIndex, BSTR *pstrSrcCarrier, BSTR *pstrSrcSlotList, BSTR *pstrDestCarrier, BSTR *pstrDestSlotList)	{		return EZGEM_GetCtrlJobMtrlOutInfo(pGEM, szCtrlJobID, nMapIndex, pstrSrcCarrier, pstrSrcSlotList, pstrDestCarrier, pstrDestSlotList);	}
//	long GetPrJobInCtrlJob(LPCTSTR szCtrlJobID, int nIndex, BSTR *pstrPrJobID)	{	return EZGEM_GetPrJobInCtrlJob(pGEM, szCtrlJobID, nIndex, pstrPrJobID);	}
	long GetCtrlJobCount()	{	return EZGEM_GetCtrlJobCount(pGEM);	}
	long GetCtrlJobSpace()	{	return EZGEM_GetCtrlJobSpace(pGEM);	}
	long GetCtrlJobCommand(long lMsgId, BSTR *pstrCJobID, int *pnCommand) { return EZGEM_GetCtrlJobCommand(pGEM, lMsgId, pstrCJobID, pnCommand); }
	long GetCtrlJobCommand(long lMsgId, CString* pstrCJobID, int* pnCommand)
	{
		BSTR bstrCJobID = nullptr;
		long lResult = EZGEM_GetCtrlJobCommand(pGEM, lMsgId, &bstrCJobID, pnCommand);
		if (lResult < 0) return lResult;
		*pstrCJobID = CString(bstrCJobID);
		::SysFreeString(bstrCJobID);
		return lResult;
	}
	long GetCtrlJobCommand(long lMsgId, CString& strCJobID, int* pnCommand)
	{
		BSTR bstrCJobID = nullptr;
		long lResult = EZGEM_GetCtrlJobCommand(pGEM, lMsgId, &bstrCJobID, pnCommand);
		if (lResult < 0) return lResult;
		strCJobID = CString(bstrCJobID);
		::SysFreeString(bstrCJobID);
		return lResult;
	}
	long GetCtrlJobDeleted(BSTR *pstrCJobID) { return EZGEM_GetCtrlJobDeleted(pGEM, pstrCJobID); }
	long GetCtrlJobDeleted(CString* pstrCJobID)
	{
		BSTR bstrCJobID = nullptr;
		long lResult = EZGEM_GetCtrlJobDeleted(pGEM, &bstrCJobID);
		if (lResult < 0) return lResult;
		*pstrCJobID = CString(bstrCJobID);
		::SysFreeString(bstrCJobID);
		return lResult;
	}
	long GetCtrlJobDeleted(CString& strCJobID)
	{
		BSTR bstrCJobID = nullptr;
		long lResult = EZGEM_GetCtrlJobDeleted(pGEM, &bstrCJobID);
		if (lResult < 0) return lResult;
		strCJobID = CString(bstrCJobID);
		::SysFreeString(bstrCJobID);
		return lResult;
	}
	long ReplyCtrlJob(long lMsgId)	{	return EZGEM_ReplyCtrlJob(pGEM, lMsgId);	}
	long ReplyCtrlJobCommand(long lMsgId) { return EZGEM_ReplyCtrlJobCommand(pGEM, lMsgId); }
	long SetCtrlJobErrorCode(long lMsgId, int nErrorCode, LPCTSTR szErrorText)	{	return EZGEM_SetCtrlJobErrorCode(pGEM, lMsgId, nErrorCode, szErrorText);	}
//	long DeleteCtrlJob(LPCTSTR szCtrlJobID)	{	return EZGEM_DeleteCtrlJob(pGEM, szCtrlJobID);	}
	long DeleteAllCtrlJob()	{	return EZGEM_DeleteAllCtrlJob(pGEM);	}
//	long SetCtrlJobState(LPCTSTR szCtrlJobID, int nState)	{	return EZGEM_SetCtrlJobState(pGEM, szCtrlJobID, nState);	}
//	long GetCtrlJobState(LPCTSTR szCtrlJobID, int *pnState)	{	return EZGEM_GetCtrlJobState(pGEM, szCtrlJobID, pnState);	}
//	long CreateCtrlJob(LPCTSTR sCtrlJobID, LPCTSTR sPrJobList, int nAutoStat)	{		return EZGEM_CreateCtrlJob(pGEM,sCtrlJobID,sPrJobList,nAutoStat);	}
//	long AddCtrlJobCarrierInputSpec(LPCTSTR szCtrlJobID, LPCTSTR szCarrierID)	{		return EZGEM_AddCtrlJobCarrierInputSpec(pGEM, szCtrlJobID, szCarrierID);	}
//	long AddCtrlJobMtrlOutSpec(LPCTSTR szCtrlJobID, LPCTSTR szSrcCarrierID, LPCTSTR szSrcSlotList, LPCTSTR szDestCarrierID, LPCTSTR szDestSlotList)	{		return EZGEM_AddCtrlJobMtrlOutSpec(pGEM, szCtrlJobID, szSrcCarrierID, szSrcSlotList, szDestCarrierID, szDestSlotList);	}

	// STS
	long CreateSubstLoc(LPCTSTR sLocID) { return EZGEM_CreateSubstLoc(pGEM, sLocID); }
	long CreateSubstBatchLoc(LPCTSTR sBatchLocID) { return EZGEM_CreateSubstBatchLoc(pGEM, sBatchLocID); }
	long CreateSubstrate(LPCTSTR sSubstID) { return EZGEM_CreateSubstrate(pGEM, sSubstID); }

	long GetSubstLocCount()	{		return EZGEM_GetSubstLocCount(pGEM);	}
	long GetSubstBatchLocCount()	{		return EZGEM_GetSubstBatchLocCount(pGEM);	}
	long GetSubstrateCount()	{		return	EZGEM_GetSubstrateCount(pGEM);	}
	long GetSubstrate(long nIndex, BSTR *psSubstID, BSTR *psCurrentLoc)	{		return EZGEM_GetSubstrate(pGEM, nIndex, psSubstID, psCurrentLoc);	}
	long GetSubstrate(long nIndex, CString* pSubstID, CString* pCurrentLoc)
	{
		BSTR bstrSubstID = nullptr;
		BSTR bstrCurrentLoc = nullptr;
		long lResult = EZGEM_GetSubstrate(pGEM, nIndex, &bstrSubstID, &bstrCurrentLoc);
		if (lResult < 0) return lResult;
		if (bstrSubstID)
		{
			*pSubstID = CString(bstrSubstID);
			::SysFreeString(bstrSubstID);
		}
		if (bstrCurrentLoc)
		{
			*pCurrentLoc = CString(bstrCurrentLoc);
			::SysFreeString(bstrCurrentLoc);
		}
		return lResult;
	}
	long GetSubstrate(long nIndex, CString& strSubstID, CString& strCurrentLoc)
	{
		BSTR bstrSubstID = nullptr;
		BSTR bstrCurrentLoc = nullptr;
		long lResult = EZGEM_GetSubstrate(pGEM, nIndex, &bstrSubstID, &bstrCurrentLoc);
		if (lResult < 0) return lResult;
		if (bstrSubstID)
		{
			strSubstID = CString(bstrSubstID);
			::SysFreeString(bstrSubstID);
		}
		if (bstrCurrentLoc)
		{
			strCurrentLoc = CString(bstrCurrentLoc);
			::SysFreeString(bstrCurrentLoc);
		}
		return lResult;
	}
	long GetSubstrateState(LPCTSTR sSubstID, int *pnTranState, int *pnProcState, int *pnReadState)	{		return EZGEM_GetSubstrateState(pGEM, sSubstID, pnTranState, pnProcState, pnReadState);	}
	long GetSubstLocation(long nIndex, BSTR *psLocID, BSTR *psSubstID, int *pnLocState)	{		return EZGEM_GetSubstLocation(pGEM, nIndex, psLocID, psSubstID, pnLocState);	}
	long GetSubstLocation(long nIndex, CString* pLocID, CString* pSubstID, int* pnLocState)
	{
		BSTR bstrLocID = nullptr;
		BSTR bstrSubstID = nullptr;
		long lResult = EZGEM_GetSubstLocation(pGEM, nIndex, &bstrLocID, &bstrSubstID, pnLocState);
		if (lResult < 0) return lResult;
		if (bstrLocID)
		{
			*pLocID = CString(bstrLocID);
			::SysFreeString(bstrLocID);
		}
		if (bstrSubstID)
		{
			*pSubstID = CString(bstrSubstID);
			::SysFreeString(bstrSubstID);
		}
		return lResult;
	}
	long GetSubstLocation(long nIndex, CString& strLocID, CString& strSubstID, int* pnLocState)
	{
		BSTR bstrLocID = nullptr;
		BSTR bstrSubstID = nullptr;
		long lResult = EZGEM_GetSubstLocation(pGEM, nIndex, &bstrLocID, &bstrSubstID, pnLocState);
		if (lResult < 0) return lResult;
		if (bstrLocID)
		{
			strLocID = CString(bstrLocID);
			::SysFreeString(bstrLocID);
		}
		if (bstrSubstID)
		{
			strSubstID = CString(bstrSubstID);
			::SysFreeString(bstrSubstID);
		}
		return lResult;
	}

	long GetSubstBatchLoc(long nIndex, CString *psBatchLocID, int *pnSubstCount, CStringArray *paSubstList)
	{
		BSTR bstrBatchLocID;
		char *psSubstList[SLOTMAP_MAXSLOT];
		for (int i = 0; i < SLOTMAP_MAXSLOT; i++) psSubstList[i] = new char[0xFF];
		long nResult = EZGEM_GetSubstBatchLoc(pGEM, nIndex, &bstrBatchLocID, pnSubstCount, psSubstList);
		if (SUCCEEDED(nResult))
		{
			for (int i = 0; i < *pnSubstCount; i++) paSubstList->Add((CString)psSubstList[i]);
		}
		for (int i = 0; i < SLOTMAP_MAXSLOT; i++) delete[]psSubstList[i];
		*psBatchLocID = (CString)bstrBatchLocID;
		SysFreeString(bstrBatchLocID);
		return nResult;
	}
	long GetSubstBatchLoc(long nIndex, CString* psBatchLocID, int* pnSubstCount, CStringArray& paSubstList)
	{
		BSTR bstrBatchLocID;
		char* psSubstList[SLOTMAP_MAXSLOT];
		for (int i = 0; i < SLOTMAP_MAXSLOT; i++) psSubstList[i] = new char[0xFF];
		long nResult = EZGEM_GetSubstBatchLoc(pGEM, nIndex, &bstrBatchLocID, pnSubstCount, psSubstList);
		if (nResult >= 0)
		{
			for (int i = 0; i < *pnSubstCount; i++)
				paSubstList.Add((CString)psSubstList[i]);
		}
		for (int i = 0; i < SLOTMAP_MAXSLOT; i++)
			delete[] psSubstList[i];
		*psBatchLocID = (CString)bstrBatchLocID;
		SysFreeString(bstrBatchLocID);
		return nResult;
	}
	long GetSubstBatchLoc(long nIndex, CString* psBatchLocID, int* pnSubstCount, std::vector<CString>& paSubstList)
	{
		BSTR bstrBatchLocID = nullptr;
		char* psSubstList[SLOTMAP_MAXSLOT];
		for (int i = 0; i < SLOTMAP_MAXSLOT; i++)
			psSubstList[i] = new char[0xFF];
		long nResult = EZGEM_GetSubstBatchLoc(pGEM, nIndex, &bstrBatchLocID, pnSubstCount, psSubstList);
		if (nResult >= 0)
		{
			for (int i = 0; i < *pnSubstCount; i++)
				paSubstList.emplace_back(psSubstList[i]);
		}
		for (int i = 0; i < SLOTMAP_MAXSLOT; i++)
			delete[] psSubstList[i];
		if (bstrBatchLocID)
		{
			*psBatchLocID = CString(bstrBatchLocID);
			::SysFreeString(bstrBatchLocID);
		}
		return nResult;
	}

	long GetSubstHostCommand(long lMsgId, int *pnCommand, BSTR *psSubstID, BSTR *psLocID)	{		return EZGEM_GetSubstHostCommand(pGEM, lMsgId, pnCommand, psSubstID, psLocID);	}
	long GetSubstHostCommand(long lMsgId, int* pnCommand, CString* pSubstID, CString* pLocID)
	{
		BSTR bstrSubstID = nullptr;
		BSTR bstrLocID = nullptr;
		long lResult = EZGEM_GetSubstHostCommand(pGEM, lMsgId, pnCommand, &bstrSubstID, &bstrLocID);
		if (lResult < 0) return lResult;
		if (bstrSubstID)
		{
			*pSubstID = CString(bstrSubstID);
			::SysFreeString(bstrSubstID);
		}
		if (bstrLocID)
		{
			*pLocID = CString(bstrLocID);
			::SysFreeString(bstrLocID);
		}
		return lResult;
	}
	long GetSubstHostCommand(long lMsgId, int* pnCommand, CString& strSubstID, CString& strLocID)
	{
		BSTR bstrSubstID = nullptr;
		BSTR bstrLocID = nullptr;
		long lResult = EZGEM_GetSubstHostCommand(pGEM, lMsgId, pnCommand, &bstrSubstID, &bstrLocID);
		if (lResult < 0) return lResult;
		if (bstrSubstID)
		{
			strSubstID = CString(bstrSubstID);
			::SysFreeString(bstrSubstID);
		}
		if (bstrLocID)
		{
			strLocID = CString(bstrLocID);
			::SysFreeString(bstrLocID);
		}
		return lResult;
	}
	long DeleteAllSubstrate()	{		return EZGEM_DeleteAllSubstrate(pGEM);	}
	long DeleteSubstrate(LPCTSTR sSubstID)	{		return EZGEM_DeleteSubstrate(pGEM, sSubstID);	}
	long SetSubstrateMove(LPCTSTR sSubstID, LPCTSTR sToLocID, int nTransferState) {		return EZGEM_SetSubstrateMove(pGEM, sSubstID, sToLocID, nTransferState);	}
	long SetSubstBatchMove(int nCount, CStringArray *psaSubstList, LPCTSTR sBatchLocID, int nStartPosInBatch, int nTransState)
	{
		BSTR *bstrSubstList = NULL;
		if (nCount > 0) bstrSubstList = new BSTR[nCount];
		for (int i = 0; i < nCount; i++) bstrSubstList[i] = (psaSubstList->GetAt(i)).AllocSysString();
		long nResult = EZGEM_SetSubstBatchMove(pGEM, nCount, bstrSubstList, sBatchLocID, nStartPosInBatch, nTransState);
		for (int i = 0; i < nCount; i++) SysFreeString(bstrSubstList[i]);
		delete[] bstrSubstList; bstrSubstList = NULL;
		return nResult;
	}
	long SetSubstTranState(LPCTSTR sSubstID, int nTranState){return EZGEM_SetSubstTranState(pGEM, sSubstID, nTranState);}
	long SetSubstProcState(LPCTSTR sSubstID, int nProcState){return EZGEM_SetSubstProcState(pGEM, sSubstID, nProcState);}
	long SetSubstReadState(LPCTSTR sSubstID, int nReadState){return EZGEM_SetSubstReadState(pGEM, sSubstID, nReadState);}
	long SetSubstIdRead(LPCTSTR sSubstID, LPCTSTR sReadID, int nReadResult) { return EZGEM_SetSubstIDRead(pGEM, sSubstID, sReadID, nReadResult); }
	//long ReplySubstAction(long lMsgId, int nRetCode, int nErrCode, LPCTSTR szErrText) { return EZGEM_ReplySubstAction(pGEM, lMsgId, nRetCode, nErrCode, szErrText); }
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////

	/*
	#ifdef UNICODE
		
	#else
		
	#endif
	*/

	void  SetIP(CString strIP)
	{
#ifdef _UNICODE
		char* szIP = SetWCharToChar(strIP.GetBuffer());
		EZGEM_SetIP(pGEM, (LPCTSTR)(LPSTR)szIP);
		free(szIP);
#else
		EZGEM_SetIP(pGEM, strIP.GetBuffer());
#endif

		
	}
	short  AddAsciiItem(long lMsgId, CString strValue)
	{
		short nAck = 0;
		int len = 0;
#ifdef _UNICODE
		len = WideCharToMultiByte(CP_ACP, 0, strValue, -1, NULL, 0, NULL, NULL);
		char* szValue = SetWCharToChar(strValue.GetBuffer());
		if (len == 0)
			len = 1;
		nAck = EZGEM_AddAsciiItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)szValue, len - 1);
		free(szValue);
#else
		len = strValue.GetLength();
		nAck = EZGEM_AddAsciiItem(pGEM, lMsgId, strValue.GetBuffer(), len);
#endif
		return nAck;
	}

	short  AddAsciiItem(long lMsgId, CString strValue, int nLen)
	{
		short nAck = 0;
		int len = 0;
#ifdef UNICODE
		len = WideCharToMultiByte(CP_ACP, 0, strValue, -1, NULL, 0, NULL, NULL);
		char* szValue = SetWCharToChar(strValue.GetBuffer());
		if (len == 0)
			len = 1;
		nAck = EZGEM_AddAsciiItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)szValue, nLen);
		free(szValue);
#else
		len = strValue.GetLength();
		nAck = EZGEM_AddAsciiItem(pGEM, lMsgId, strValue.GetBuffer(), nLen);
#endif
		return nAck;
	}


	short  AddJ8Item(long lMsgId, CString strValue, int nLen)
	{
		short nAck = 0;
		int len = 0;
#ifdef UNICODE
		len = WideCharToMultiByte(CP_ACP, 0, strValue, -1, NULL, 0, NULL, NULL);
		char* szValue = SetWCharToChar(strValue.GetBuffer());
		if (len == 0)
			len = 1;
		nAck = EZGEM_AddJ8Item(pGEM, lMsgId, (LPCTSTR)(LPSTR)szValue, nLen);
		free(szValue);
#else
		len = strValue.GetLength();
		nAck = EZGEM_AddAsciiItem(pGEM, lMsgId, strValue.GetBuffer(), nLen);
#endif
		return nAck;
	}


	//	short  AddJ8Item(long lMsgId, LPCTSTR pszValue, long lCount) { return EZGEM_AddJ8Item(pGEM, lMsgId, pszValue, lCount); }

	void   SetLogFile(CString strFileName, short bLogSecsII)
	{
#ifdef UNICODE
		char* szLog = SetWCharToChar(strFileName.GetBuffer());
		EZGEM_SetLogFile(pGEM, (LPCTSTR)(LPSTR)szLog, bLogSecsII);
		free(szLog);
#else
		EZGEM_SetLogFile(pGEM, strFileName.GetBuffer(), bLogSecsII);
#endif
	}

	void   SetFormatFile(CString strFormatFile)
	{
#ifdef UNICODE
		char* szFormat = SetWCharToChar(strFormatFile.GetBuffer());
		EZGEM_SetFormatFile(pGEM, (LPCTSTR)szFormat);
		free(szFormat);
#else
		EZGEM_SetFormatFile(pGEM, strFormatFile.GetBuffer());
#endif
	}

	long   AddFileBinaryItem(long lMsgId, CString strFile)
	{
#ifdef UNICODE
		char* szFileName = SetWCharToChar(strFile.GetBuffer());
		long lReturn = EZGEM_AddFileBinaryItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)szFileName);
		free(szFileName);
#else
		long lReturn = EZGEM_AddFileBinaryItem(pGEM, lMsgId, strFile.GetBuffer());
#endif
		return lReturn;
	}

	long   GetFileBinaryItem(long lMsgId, CString strFile)
	{
#ifdef UNICODE
		char* szFileName = SetWCharToChar(strFile.GetBuffer());
		long lReturn = EZGEM_GetFileBinaryItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)szFileName);
		free(szFileName);
#else
		long lReturn = EZGEM_GetFileBinaryItem(pGEM, lMsgId, strFile.GetBuffer());
#endif
		return lReturn;
	}

	void   SetConfigFile(CString strConfigFile)
	{
#ifdef UNICODE
		char* szFileName = SetWCharToChar(strConfigFile.GetBuffer());
		EZGEM_SetConfigFile(pGEM, (LPCTSTR)(LPSTR)szFileName);
		free(szFileName);
#else
		EZGEM_SetConfigFile(pGEM, strConfigFile.GetBuffer());
#endif
		
	}

	void   SaveConfigFile(CString strConfigFile)
	{
#ifdef UNICODE
		char* szFileName = SetWCharToChar(strConfigFile.GetBuffer());
		EZGEM_SaveConfigFile(pGEM, (LPCTSTR)(LPSTR)szFileName);
		free(szFileName);
#else
		EZGEM_SaveConfigFile(pGEM, strConfigFile.GetBuffer());
#endif
		
	}

	short  SeparateLog(CString strLogFileName, short nStream, short nFunction)
	{
		short nReturn = 0;
#ifdef UNICODE
		char* szFileName = SetWCharToChar(strLogFileName.GetBuffer());
		nReturn = EZGEM_SeparateLog(pGEM, (LPCTSTR)(LPSTR)szFileName, nStream, nFunction);
		free(szFileName);
#else
		nReturn = EZGEM_SeparateLog(pGEM, strLogFileName.GetBuffer(), nStream, nFunction);
#endif
		
		return nReturn;
	}

	long   AddArrayItem(long lMsgId, CString strType, long nDataCount, CString strData)
	{
		long lReturn = 0;
#ifdef UNICODE
		char* szType = SetWCharToChar(strType.GetBuffer());
		char* szData = SetWCharToChar(strData.GetBuffer());
		lReturn = EZGEM_AddArrayItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)szType, nDataCount, (LPCTSTR)(LPSTR)szData);
		free(szType);
		free(szData);
#else
		lReturn = EZGEM_AddArrayItem(pGEM, lMsgId, strType.GetBuffer(), nDataCount, strData.GetBuffer());
#endif

		return lReturn;
	}
	void   WriteUserLog(CString strLog)
	{
#ifdef UNICODE
		char* szLog = SetWCharToChar(strLog.GetBuffer());
		EZGEM_WriteUserLog(pGEM, (LPCTSTR)(LPSTR)szLog);
		free(szLog);
#else
		EZGEM_WriteUserLog(pGEM, strLog.GetBuffer());
#endif
	}
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void   SetModelName(CString strModelName) 
	{
#ifdef UNICODE
		char* szModelName = SetWCharToChar(strModelName.GetBuffer());
		EZGEM_SetModelName(pGEM, szModelName);
		free(szModelName);
#else
		EZGEM_SetModelName(pGEM, strModelName.GetBuffer());
#endif
	}

	void   SetSoftRev(CString strSoftRev)
	{
#ifdef UNICODE
		char* szSoftRev = SetWCharToChar(strSoftRev.GetBuffer());
		EZGEM_SetSoftRev(pGEM, szSoftRev);
		free(szSoftRev);
#else
		EZGEM_SetSoftRev(pGEM, strSoftRev.GetBuffer());
#endif
	}

	long   AddCEID(long CEID, CString strName, CString strDescription)
	{
		long lReturn = 0;
#ifdef UNICODE
		char* szName = SetWCharToChar(strName.GetBuffer());
		char* szDesc = SetWCharToChar(strDescription.GetBuffer());
		lReturn = EZGEM_AddCEID(pGEM, CEID, szName, szDesc);
		free(szName);
		free(szDesc);
#else
		lReturn = EZGEM_AddCEID(pGEM, CEID, strName.GetBuffer(), strDescription.GetBuffer());
#endif
		return lReturn;
	}

	long   AddSVID(long SVID, CString strName, CString strFormat, CString strUnit)
	{
#ifdef UNICODE
		char* szName = SetWCharToChar(strName.GetBuffer());
		char* szFormat = SetWCharToChar(strFormat.GetBuffer());
		char* szUnit = SetWCharToChar(strUnit.GetBuffer());
		long lReturn = EZGEM_AddSVID(pGEM, SVID, szName, szFormat, szUnit);
		free(szName);
		free(szFormat);
		free(szUnit);
#else
		long lReturn = EZGEM_AddSVID(pGEM, SVID, strName.GetBuffer(), strFormat.GetBuffer(), strUnit.GetBuffer());
#endif
		return lReturn;
	}

	long   AddDVID(long DVID, CString strName, CString strFormat)
	{
#ifdef UNICODE
		char* szName = SetWCharToChar(strName.GetBuffer());
		char* szFormat = SetWCharToChar(strFormat.GetBuffer());
		long lReturn = EZGEM_AddDVID(pGEM, DVID, szName, szFormat);
		free(szName);
		free(szFormat);
#else
		long lReturn = EZGEM_AddDVID(pGEM, DVID, strName.GetBuffer(), strFormat.GetBuffer());
#endif
		return lReturn;
	}

	long   AddALID(long ALID, CString strName, CString strALCD)
	{
#ifdef UNICODE
		char* szName = SetWCharToChar(strName.GetBuffer());
		char* szALCD = SetWCharToChar(strALCD.GetBuffer());
		long lReturn = EZGEM_AddALID(pGEM, ALID, szName, szALCD);
		free(szName);
		free(szALCD);
#else
		long lReturn = EZGEM_AddALID(pGEM, ALID, strName.GetBuffer(), strALCD.GetBuffer());
#endif
		return lReturn;
	}

	long   AddECID(long ECID, CString strName, CString strUnit, CString strFormat)
	{
#ifdef UNICODE
		char* szName = SetWCharToChar(strName.GetBuffer());
		char* szUnit = SetWCharToChar(strUnit.GetBuffer());
		char* szFormat = SetWCharToChar(strFormat.GetBuffer());
		long lReturn = EZGEM_AddECID(pGEM, ECID, szName, szUnit, szFormat);
		free(szName);
		free(szFormat);
		free(szUnit);
#else
		long lReturn = EZGEM_AddECID(pGEM, ECID, strName.GetBuffer(), strUnit.GetBuffer(), strFormat.GetBuffer());
#endif
		return lReturn;
	}

	long   AddRemoteCommand(CString strCommand)
	{
#ifdef UNICODE
		char* szCommand = SetWCharToChar(strCommand.GetBuffer());
		long bReturn = EZGEM_AddRemoteCommand(pGEM, szCommand);
		free(szCommand);
#else
		long bReturn = EZGEM_AddRemoteCommand(pGEM, strCommand.GetBuffer());
#endif
		return bReturn;
	}

	long   SetSVIDValue(long SVID, CString strValue)
	{
#ifdef UNICODE
		char* szValue = SetWCharToChar(strValue.GetBuffer());
		long bReturn = EZGEM_SetSVIDValue(pGEM, SVID, szValue);
		free(szValue);
#else
		long bReturn = EZGEM_SetSVIDValue(pGEM, SVID, strValue.GetBuffer());
#endif
		return bReturn;
	}

	long   SetVIDValue(long VID, CString strValue)
	{
#ifdef UNICODE
		char* szValue = SetWCharToChar(strValue.GetBuffer());
		long bReturn = EZGEM_SetVIDValue(pGEM, VID, szValue);
		free(szValue);
#else
		long bReturn = EZGEM_SetVIDValue(pGEM, VID, strValue.GetBuffer());
#endif
		return bReturn;
	}

	short  SetECValue(long ECID, CString strValue)
	{
#ifdef UNICODE
		char* szValue = SetWCharToChar(strValue.GetBuffer());
		short nReturn = EZGEM_SetECValue(pGEM, ECID, szValue);
		free(szValue);
#else
		short nReturn = EZGEM_SetECValue(pGEM, ECID, strValue.GetBuffer());
#endif
		return nReturn;
	}

	short  SetECRange(long ECID, CString strMinValue, CString strMaxValue)
	{
#ifdef UNICODE
		char* szMinValue = SetWCharToChar(strMinValue.GetBuffer());
		char* szMaxValue = SetWCharToChar(strMaxValue.GetBuffer());
		short Return = EZGEM_SetECRange(pGEM, ECID, szMinValue, szMaxValue);
		free(szMinValue);
		free(szMaxValue);
#else
		short Return = EZGEM_SetECRange(pGEM, ECID, strMinValue.GetBuffer(), strMaxValue.GetBuffer());
#endif
		return Return;
	}

	void   SetReportFilePath(CString strFilePath)
	{
#ifdef UNICODE
		char* szFilePath = SetWCharToChar(strFilePath.GetBuffer());
		long bReturn = EZGEM_AddRemoteCommand(pGEM, szFilePath);
		free(szFilePath);
#else
		long bReturn = EZGEM_AddRemoteCommand(pGEM, strFilePath.GetBuffer());
#endif
	}

	short  SetFormatCode(CString strItemName, CString strFormatCode)
	{
#ifdef UNICODE
		char* szItemName = SetWCharToChar(strItemName.GetBuffer());
		char* szFormatCode = SetWCharToChar(strFormatCode.GetBuffer());

		short Return = EZGEM_SetFormatCode(pGEM, szItemName, szFormatCode);
		free(szItemName);
		free(szFormatCode);
#else
		short Return = EZGEM_SetFormatCode(pGEM, strItemName.GetBuffer(), strFormatCode.GetBuffer());
#endif
		return Return;
	}

	void SetRemoteCommandErrorCode(long lMsgId, CString strCommand, short nParamIndex, short nErrorCode)
	{
#ifdef UNICODE
		char* szCommand = SetWCharToChar(strCommand.GetBuffer());
		EZGEM_SetRemoteCommandErrorCode(pGEM, lMsgId, (LPCTSTR)(LPSTR)szCommand, nParamIndex, nErrorCode);
		free(szCommand);
#else
		EZGEM_SetRemoteCommandErrorCode(pGEM, lMsgId, strCommand.GetBuffer(), nParamIndex, nErrorCode);
#endif
	}

	long SaveMsgToFile(long lMsgId, CString sFile)
	{
#ifdef UNICODE
		char* szFile = SetWCharToChar(sFile.GetBuffer());
		long lAck = EZGEM_SaveMsgToFile(pGEM, lMsgId, (LPCTSTR)(LPSTR)szFile);
		free(szFile);
#else
		long lAck = EZGEM_SaveMsgToFile(pGEM, lMsgId, sFile.GetBuffer());
#endif
		return lAck;
	}
	long SetOption(CString sOptionName, int nOptionVal)
	{
#ifdef UNICODE
		char* szOption = SetWCharToChar(sOptionName.GetBuffer());
		long lAck = EZGEM_SetOption(pGEM, (LPCTSTR)(LPSTR)szOption, nOptionVal);
		free(szOption);
#else
		long lAck = EZGEM_SetOption(pGEM, sOptionName.GetBuffer(), nOptionVal);
#endif
		return lAck;
	}
	long SendMsgFromFile(CString sFile)
	{
#ifdef UNICODE
		char* szFile = SetWCharToChar(sFile.GetBuffer());
		long lAck = EZGEM_SendMsgFromFile(pGEM, (LPCTSTR)(LPSTR)szFile);
		free(szFile);
#else
		long lAck = EZGEM_SendMsgFromFile(pGEM, sFile.GetBuffer());
#endif
		return lAck;
	}

	long GetListChildItem(long lMsgId, CString sDelimiter, BSTR* psValue, long* plLength)
	{
		long lAck = 0;
#ifdef UNICODE
		char* pszDelimiter = SetWCharToChar(sDelimiter.GetBuffer());
		lAck = EZGEM_GetListChildItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)pszDelimiter, psValue, plLength);
		free(pszDelimiter);
#else
		lAck = EZGEM_GetListChildItem(pGEM, lMsgId, sDelimiter.GetBuffer(), psValue, plLength);
#endif
		return lAck;
	}

	long  GetListChildItem(long lMsgId, CStringArray* pValueList)
	{
		BSTR bstrValue;
		long lLength = 0;
		long nResult = GetListChildItem(lMsgId, _T(","), &bstrValue, &lLength);
		if (nResult < 0) return nResult;

#ifdef UNICODE
		wstring str;
		wstringstream ssValue((wstring)(CString)bstrValue);
		while (getline(ssValue, str, _T(','))) pValueList->Add(str.c_str());
		if (pValueList->GetSize() == nResult - 1) pValueList->Add(_T(""));

#else
		string str;
		stringstream ssValue((string)(CString)bstrValue);
		while (getline(ssValue, str, ',')) pValueList->Add(str.c_str());
		if (pValueList->GetSize() == nResult - 1) pValueList->Add("");
#endif
		//-------------------------------------------
		
		return nResult;
	}

	long  GetNameValueListItem(long lMsgId, CString sDelimiter, BSTR* psNameList, BSTR* psValueList, long* plCount) 
	{
		long lAck = 0;
#ifdef UNICODE
		char* psDelimiter = SetWCharToChar(sDelimiter.GetBuffer());
		lAck = EZGEM_GetNameValueListItem(pGEM, lMsgId, (LPCTSTR)(LPSTR)psDelimiter, psNameList, psValueList, plCount);
#else
		lAck = EZGEM_GetNameValueListItem(pGEM, lMsgId, sDelimiter.GetBuffer() , psNameList, psValueList, plCount);
#endif
		return lAck;
	}

	long  GetNameValueListItem(long lMsgId, CStringArray* pNameList, CStringArray* pValueList)
	{
		BSTR bstrName, bstrVal;
		long lCount = 0;
		long nResult = GetNameValueListItem(lMsgId, _T(","), &bstrName, &bstrVal, &lCount);
		if (nResult < 0) return nResult;
		//-------------------------------------------
#ifdef UNICODE
		wstring str;
		wstringstream ssName((wstring)(CString)bstrName);
		wstringstream ssValue((wstring)(CString)bstrVal);
		while (getline(ssName, str, _T(','))) pNameList->Add(str.c_str());
		while (getline(ssValue, str, _T(','))) pValueList->Add(str.c_str());
		if (pValueList->GetSize() == pNameList->GetSize() - 1) pValueList->Add(_T(""));
#else
		string str;
		stringstream ssName((string)(CString)bstrName);
		stringstream ssValue((string)(CString)bstrVal);
		while (getline(ssName, str, ',')) pNameList->Add(str.c_str());
		while (getline(ssValue, str, ',')) pValueList->Add(str.c_str());
		if (pValueList->GetSize() == pNameList->GetSize() - 1) pValueList->Add("");
#endif
		return lCount;
	}

	void  GetVersionInfo(CString* strVersionInfo)
	{
		BSTR bstVersionInfo;
		EZGEM_GetVersionInfo(pGEM, &bstVersionInfo);
		strVersionInfo->Format(_T("%s"), bstVersionInfo);
		SysFreeString(bstVersionInfo);
	}
	long  GetItemInfo(long lMsgId, CString strItemPos, short *pnFormat, long *plCount) 
	{ 
#ifdef UNICODE
		char* pszItemPos = SetWCharToChar(strItemPos.GetBuffer());
		long nResult = EZGEM_GetItemInfo(pGEM, lMsgId, (LPCTSTR)(LPSTR)pszItemPos, pnFormat, plCount);
		free(pszItemPos);
#else
		long nResult = EZGEM_GetItemInfo(pGEM, lMsgId, (LPCTSTR)(LPSTR)strItemPos.GetBuffer(), pnFormat, plCount);
#endif
		return nResult;
	}
	long  GetItemValue(long lMsgId, CString strItemPos, BSTR *psValue)
	{
#ifdef UNICODE
		char* pszItemPos = SetWCharToChar(strItemPos.GetBuffer());
		long nResult = EZGEM_GetItemValue(pGEM, lMsgId, (LPCTSTR)(LPSTR)pszItemPos, psValue);
		free(pszItemPos);
#else
		long nResult = EZGEM_GetItemValue(pGEM, lMsgId, (LPCTSTR)(LPSTR)strItemPos.GetBuffer(), psValue);
#endif
		return nResult;
	}
	long  GetAsciiItem(long lMsgId, CString* strBuff)
	{
		BSTR bstrBuff;
		long nSize = EZGEM_GetAsciiItem(pGEM, lMsgId, &bstrBuff);

		if (nSize == 0)
		{
			SysFreeString(bstrBuff);
			return nSize;
		}
		if (nSize > 16000)
		{
			char* buff;// [0xfffff] ;
			buff = (char*)malloc(600000);

			WideCharToMultiByte(CP_ACP, 0, bstrBuff, -1, buff, nSize, NULL, NULL);
			CString strTemp = (CString)buff;
			strTemp.TrimRight();
			*strBuff = strTemp;
			SysFreeString(bstrBuff);
			if (buff != NULL)
				free(buff);
		}
		else {
			char buff[16000];
			memset(buff, '\0', 16000);

			WideCharToMultiByte(CP_ACP, 0, bstrBuff, -1, buff, nSize, NULL, NULL);
			CString strTemp = (CString)buff;
			strTemp.TrimRight();
			*strBuff = strTemp;
			SysFreeString(bstrBuff);
			memset(buff, '\0', 16000);
		}

		return nSize;
	}

	//----------------------------------------------------------------------------
	//	GEM300 API
	//  CMS
	//	overriding code for UNICODE
	long SetLoadPort(int nPortID, int nTransferState, int nAccessMode, CString strLocationName, CString strCarrierID)
	{
		long lAck = 0;

#ifdef UNICODE
		char* pszLocationName = SetWCharToChar(strLocationName.GetBuffer());
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		lAck = EZGEM_SetLoadPort(pGEM, nPortID, nTransferState, nAccessMode, (LPCTSTR)(LPSTR)pszLocationName, (LPCTSTR)(LPSTR)pszCarrierID);
		free(pszLocationName);
		free(pszCarrierID);
#else
		lAck = EZGEM_SetLoadPort(pGEM, nPortID, nTransferState, nAccessMode, strLocationName.GetBuffer(), strCarrierID.GetBuffer());
#endif
		return lAck;
	}
	long SetCarrierAccessState(int nPortID, int nState, CString strCarrierID)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long lAck = EZGEM_SetCarrierAccessState(pGEM, nPortID, nState, (LPCTSTR)(LPSTR)pszCarrierID);
		free(pszCarrierID);
#else
		long lAck = EZGEM_SetCarrierAccessState(pGEM, nPortID, nState, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer());
#endif
			return lAck;
	}

	long SetCarrierIDRead(int nPortID, CString strCarrierID, int nResult)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long lAck = EZGEM_SetCarrierIDRead(pGEM, nPortID, (LPCTSTR)(LPSTR)pszCarrierID, nResult);
		free(pszCarrierID);
#else
		long lAck = EZGEM_SetCarrierIDRead(pGEM, nPortID, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), nResult);
#endif
		return lAck;
	}

	long SetCarrierIDStatus(int nPortID, CString strCarrierID, int nStatus)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long lAck = EZGEM_SetCarrierIDStatus(pGEM, nPortID, (LPCTSTR)(LPSTR)pszCarrierID, nStatus);
		free(pszCarrierID);
#else
		long lAck = EZGEM_SetCarrierIDStatus(pGEM, nPortID, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), nStatus);
#endif
		return lAck;
	}

	long SetSlotMapRead(int nPortID, CString strCarrierID, CString strSlotMap, int nResult)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		char* pszSlotMap = SetWCharToChar(strSlotMap.GetBuffer());
		long lAck = EZGEM_SetSlotMapRead(pGEM, nPortID, (LPCTSTR)(LPSTR)pszCarrierID, (LPCTSTR)(LPSTR)pszSlotMap, nResult);
		free(pszCarrierID);
		free(pszSlotMap);
#else
		long lAck = EZGEM_SetSlotMapRead(pGEM, nPortID, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), (LPCTSTR)(LPSTR)strSlotMap.GetBuffer(), nResult);
#endif
		
		return lAck;
	}

	long SetSlotMapStatus(int nPortID, CString strCarrierID, int nStatus)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long lAck = EZGEM_SetSlotMapStatus(pGEM, nPortID, (LPCTSTR)(LPSTR)pszCarrierID, nStatus);
		free(pszCarrierID);
#else
		long lAck = EZGEM_SetSlotMapStatus(pGEM, nPortID, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), nStatus);
#endif
		
		return lAck;
	}

	long SetCarrierActionErrorCode(long lMsgId, int nErrorCode, CString strErrorText)
	{
#ifdef UNICODE
		char* pszErrorText = SetWCharToChar(strErrorText.GetBuffer());
		long lAck = EZGEM_SetCarrierActionErrorCode(pGEM, lMsgId, nErrorCode, (LPCTSTR)(LPSTR)pszErrorText);
		free(pszErrorText);
#else
		long lAck = EZGEM_SetCarrierActionErrorCode(pGEM, lMsgId, nErrorCode, (LPCTSTR)(LPSTR)strErrorText.GetBuffer());
#endif
		
		return lAck;
	}

	long DeleteCarrier(CString strCarrierID)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_DeleteCarrier(pGEM, (LPCTSTR)(LPSTR)pszCarrierID);
		free(pszCarrierID);
#else
		long nResult = EZGEM_DeleteCarrier(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer());
#endif
		return nResult;
	}

	long GetLoadPortInfo(int nPortID, BSTR *psLocID, BSTR *psCarrierID, int *pnAccessMode, int *pnTransferState, int *pnReservState, int *pnAssocState)
	{
		return EZGEM_GetLoadPortInfo(pGEM, nPortID, psLocID, psCarrierID, pnAccessMode, pnTransferState, pnReservState, pnAssocState);
	}
	long GetLoadPortInfo(int nPortID, CString* psLocID, CString* psCarrierID, int* pnAccessMode, int* pnTransferState, int* pnReservState, int* pnAssocState)
	{
		BSTR bstrLocID = nullptr;
		BSTR bstrCarrierID = nullptr;
		long nResult = EZGEM_GetLoadPortInfo(pGEM, nPortID, &bstrLocID, &bstrCarrierID, pnAccessMode, pnTransferState, pnReservState, pnAssocState);
		if (nResult < 0) return nResult;
		if (psLocID && bstrLocID)
		{
			*psLocID = CString(bstrLocID);
			SysFreeString(bstrLocID);
		}
		else if (psLocID)
		{
			psLocID->Empty();
		}
		if (psCarrierID && bstrCarrierID)
		{
			*psCarrierID = CString(bstrCarrierID);
			SysFreeString(bstrCarrierID);
		}
		else if (psCarrierID)
		{
			psCarrierID->Empty();
		}
		return nResult;
	}
	long GetLoadPortInfo(int nPortID, CString& strLocID, CString& strCarrierID, int* pnAccessMode, int* pnTransferState, int* pnReservState, int* pnAssocState)
	{
		BSTR bstrLocID = nullptr;
		BSTR bstrCarrierID = nullptr;
		long nResult = EZGEM_GetLoadPortInfo(pGEM, nPortID, &bstrLocID, &bstrCarrierID, pnAccessMode, pnTransferState, pnReservState, pnAssocState);
		if (nResult < 0) return nResult;
		if (bstrLocID)
		{
			strLocID = CString(bstrLocID);
			SysFreeString(bstrLocID);
		}
		else
		{
			strLocID.Empty();
		}
		if (bstrCarrierID)
		{
			strCarrierID = CString(bstrCarrierID);
			SysFreeString(bstrCarrierID);
		}
		else
		{
			strCarrierID.Empty();
		}
		return nResult;
	}

	long GetCarrierInfo(CString strCarrierID, BSTR *psLocID, int *pnIDStatus, int *pnSlotMapStatus, int *pnAccessStatus, BSTR *pstrSlotMap, BSTR *pstrUsage)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_GetCarrierInfo(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, psLocID, pnIDStatus, pnSlotMapStatus, pnAccessStatus, pstrSlotMap, pstrUsage);
		free(pszCarrierID);
#else
		long nResult = EZGEM_GetCarrierInfo(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), psLocID, pnIDStatus, pnSlotMapStatus, pnAccessStatus, pstrSlotMap, pstrUsage);
#endif
		return nResult;
	}
	long GetCarrierInfo(CString strCarrierID,CString* psLocID,int* pnIDStatus,int* pnSlotMapStatus,int* pnAccessStatus,CString* pstrSlotMap,CString* pstrUsage)
	{
		BSTR bstrLocID = nullptr;
		BSTR bstrSlotMap = nullptr;
		BSTR bstrUsage = nullptr;

#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_GetCarrierInfo(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, &bstrLocID, pnIDStatus, pnSlotMapStatus, pnAccessStatus, &bstrSlotMap, &bstrUsage);
		free(pszCarrierID);
#else
		long nResult = EZGEM_GetCarrierInfo(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), &bstrLocID, pnIDStatus, pnSlotMapStatus, pnAccessStatus, &bstrSlotMap, &bstrUsage);
#endif
		if (SUCCEEDED(nResult)) 
		{
			if (bstrLocID) 
			{
				*psLocID = CString(bstrLocID);
				::SysFreeString(bstrLocID);
			}
			else 
			{
				psLocID->Empty();
			}

			if (bstrSlotMap) 
			{
				*pstrSlotMap = CString(bstrSlotMap);
				::SysFreeString(bstrSlotMap);
			}
			else 
			{
				pstrSlotMap->Empty();
			}

			if (bstrUsage) 
			{
				*pstrUsage = CString(bstrUsage);
				::SysFreeString(bstrUsage);
			}
			else 
			{
				pstrUsage->Empty();
			}
		}
		else 
		{
			psLocID->Empty();
			pstrSlotMap->Empty();
			pstrUsage->Empty();
		}
		return nResult;
	}
	long GetCarrierInfo(CString strCarrierID,CString& sLocID,int* pnIDStatus,int* pnSlotMapStatus,int* pnAccessStatus,CString& strSlotMap,	CString& strUsage)
	{
		BSTR bstrLocID = nullptr;
		BSTR bstrSlotMap = nullptr;
		BSTR bstrUsage = nullptr;

#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_GetCarrierInfo(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, &bstrLocID, pnIDStatus, pnSlotMapStatus, pnAccessStatus, &bstrSlotMap, &bstrUsage);
		free(pszCarrierID);
#else
		long nResult = EZGEM_GetCarrierInfo(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), &bstrLocID, pnIDStatus, pnSlotMapStatus, pnAccessStatus, &bstrSlotMap, &bstrUsage);
#endif
		if (SUCCEEDED(nResult)) 
		{
			if (bstrLocID) 
			{
				sLocID = CString(bstrLocID);
				::SysFreeString(bstrLocID);
			}
			else 
			{
				sLocID.Empty();
			}

			if (bstrSlotMap) 
			{
				strSlotMap = CString(bstrSlotMap);
				::SysFreeString(bstrSlotMap);
			}
			else 
			{
				strSlotMap.Empty();
			}

			if (bstrUsage) 
			{
				strUsage = CString(bstrUsage);
				::SysFreeString(bstrUsage);
			}
			else 
			{
				strUsage.Empty();
			}
		}
		else 
		{
			sLocID.Empty();
			strSlotMap.Empty();
			strUsage.Empty();
		}
		return nResult;
	}

	long GetSlotInfo(CString strCarrierID, int nSlotNo, int *pnSlotType, BSTR *psLotID, BSTR *psSubstID)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_GetSlotInfo(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, nSlotNo, pnSlotType, psLotID, psSubstID);
		free(pszCarrierID);
#else
		long nResult = EZGEM_GetSlotInfo(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), nSlotNo, pnSlotType, psLotID, psSubstID);
#endif
		return nResult;
	}
	long GetSlotInfo(CString strCarrierID, int nSlotNo, int* pnSlotType, CString* psLotID, CString* psSubstID)
	{
		BSTR bstrLotID = nullptr;
		BSTR bstrSubstID = nullptr;

#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_GetSlotInfo(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, nSlotNo, pnSlotType, &bstrLotID, &bstrSubstID);
		free(pszCarrierID);
#else
		long nResult = EZGEM_GetSlotInfo(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), nSlotNo, pnSlotType, &bstrLotID, &bstrSubstID);
#endif
		if (SUCCEEDED(nResult)) 
		{
			if (bstrLotID) 
			{
				*psLotID = CString(bstrLotID);
				::SysFreeString(bstrLotID);
			}
			else 
			{
				psLotID->Empty();
			}

			if (bstrSubstID) 
			{
				*psSubstID = CString(bstrSubstID);
				::SysFreeString(bstrSubstID);
			}
			else 
			{
				psSubstID->Empty();
			}
		}
		else 
		{
			psLotID->Empty();
			psSubstID->Empty();
		}
		return nResult;
	}

	long CreateCarrierLoc(CString strLocationID)
	{	
#ifdef UNICODE
		char* pszLocationID = SetWCharToChar(strLocationID.GetBuffer());
		long nResult = EZGEM_CreateCarrierLoc(pGEM, (LPCTSTR)(LPSTR)pszLocationID);
		free(pszLocationID);
#else
		long nResult = EZGEM_CreateCarrierLoc(pGEM, (LPCTSTR)(LPSTR)strLocationID.GetBuffer());
#endif
		return nResult;
	}
	long SetCarrierLocInfo(CString strLocationID, CString strCarrierID)
	{	
#ifdef UNICODE
		char* pszLocationID = SetWCharToChar(strLocationID.GetBuffer());
		char* pszCarrierID  = SetWCharToChar(strCarrierID.GetBuffer());

		long nResult = EZGEM_SetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)pszLocationID, (LPCTSTR)(LPSTR)pszCarrierID);
		free(pszLocationID);
		free(pszCarrierID);
#else
		long nResult = EZGEM_SetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)strLocationID.GetBuffer(), (LPCTSTR)(LPSTR)strCarrierID.GetBuffer());
#endif
		return nResult;
	}
	long GetCarrierLocInfo(CString strLocationID, BSTR *psCarrierID)
	{
#ifdef UNICODE
		char* pszLocationID = SetWCharToChar(strLocationID.GetBuffer());
		long nResult = EZGEM_GetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)pszLocationID, psCarrierID);
		free(pszLocationID);
#else
		long nResult = EZGEM_GetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)strLocationID.GetBuffer(), psCarrierID);
#endif
		return nResult;
	}
	long GetCarrierLocInfo(CString strLocationID, CString* psCarrierID)
	{
		BSTR bstrCarrierID = nullptr;
		long nResult = -1;
#ifdef UNICODE
		char* pszLocationID = SetWCharToChar(strLocationID.GetBuffer());
		nResult = EZGEM_GetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)pszLocationID, &bstrCarrierID);
		free(pszLocationID);
#else
		nResult = EZGEM_GetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)strLocationID.GetBuffer(), &bstrCarrierID);
#endif
		if (psCarrierID)
		{
			if (SUCCEEDED(nResult))
			{
				*psCarrierID = CString(bstrCarrierID);
				SysFreeString(bstrCarrierID);
			}
			else
			{
				psCarrierID->Empty();
			}
		}
		return nResult;
	}
	long GetCarrierLocInfo(CString& strLocationID, CString& strCarrierID)
	{
		BSTR bstrCarrierID = nullptr;
		long nResult = -1;
#ifdef UNICODE
		char* pszLocationID = SetWCharToChar(strLocationID.GetBuffer());
		nResult = EZGEM_GetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)pszLocationID, &bstrCarrierID);
		free(pszLocationID);
#else
		nResult = EZGEM_GetCarrierLocInfo(pGEM, (LPCTSTR)(LPSTR)strLocationID.GetBuffer(), &bstrCarrierID);
#endif
		if (SUCCEEDED(nResult))
		{
			strCarrierID = CString(bstrCarrierID);
			SysFreeString(bstrCarrierID);
		}
		else
		{
			strCarrierID.Empty();
		}
		return nResult;
	}

	long GetCarrierLocation(CString strCarrierID, BSTR *psLocationID)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long nResult = EZGEM_GetCarrierLocation(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, psLocationID);
		free(pszCarrierID);
#else
		long nResult = EZGEM_GetCarrierLocation(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), psLocationID);
#endif
		return nResult;
	}
	long GetCarrierLocation(CString strCarrierID, CString* psLocationID)
	{
		BSTR bstrLocationID = nullptr;
		long nResult = -1;
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		nResult = EZGEM_GetCarrierLocation(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, &bstrLocationID);
		free(pszCarrierID);
#else
		nResult = EZGEM_GetCarrierLocation(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), &bstrLocationID);
#endif
		if (psLocationID)
		{
			if (SUCCEEDED(nResult))
			{
				*psLocationID = CString(bstrLocationID);
				SysFreeString(bstrLocationID);
			}
			else
			{
				psLocationID->Empty();
			}
		}
		return nResult;
	}
	long GetCarrierLocation(CString strCarrierID, CString& strLocationID)
	{
		BSTR bstrLocationID = nullptr;
		long nResult = -1;
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		nResult = EZGEM_GetCarrierLocation(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, &bstrLocationID);
		free(pszCarrierID);
#else
		nResult = EZGEM_GetCarrierLocation(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), &bstrLocationID);
#endif
		if (SUCCEEDED(nResult))
		{
			strLocationID = CString(bstrLocationID);
			SysFreeString(bstrLocationID);
		}
		else
		{
			strLocationID.Empty();
		}
		return nResult;
	}

	long SetCarrierMove(CString strCarrierID, CString strLocationID)
	{
#ifdef UNICODE
		char* pszCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		char* pszLocationID = SetWCharToChar(strLocationID.GetBuffer());
		long nResult = EZGEM_SetCarrierMove(pGEM, (LPCTSTR)(LPSTR)pszCarrierID, (LPCTSTR)(LPSTR)pszLocationID);
		free(pszCarrierID);
		free(pszLocationID);
#else
		long nResult = EZGEM_SetCarrierMove(pGEM, (LPCTSTR)(LPSTR)strCarrierID.GetBuffer(), (LPCTSTR)(LPSTR)strLocationID.GetBuffer());
#endif
		return nResult;
	}

	long GetCarrierList(long nIndex, BSTR *psCarrierID, BSTR *psLocID) { return EZGEM_GetCarrierList(pGEM, nIndex, psCarrierID, psLocID); }
	long GetCarrierList(long nIndex, CString* psCarrierID, CString* psLocID)
	{
		BSTR bstrCarrierID = nullptr;
		BSTR bstrLocID = nullptr;
		long nResult = EZGEM_GetCarrierList(pGEM, nIndex, &bstrCarrierID, &bstrLocID);
		if (SUCCEEDED(nResult))
		{
			if (psCarrierID)
			{
				if (bstrCarrierID)
				{
					*psCarrierID = CString(bstrCarrierID);
					SysFreeString(bstrCarrierID);
				}
				else
				{
					psCarrierID->Empty();
				}
			}
			if (psLocID)
			{
				if (bstrLocID)
				{
					*psLocID = CString(bstrLocID);
					SysFreeString(bstrLocID);
				}
				else
				{
					psLocID->Empty();
				}
			}
		}
		else
		{
			if (psCarrierID) psCarrierID->Empty();
			if (psLocID) psLocID->Empty();
		}
		return nResult;
	}
	long GetCarrierList(long nIndex, CString& strCarrierID, CString& strLocID)
	{
		BSTR bstrCarrierID = nullptr;
		BSTR bstrLocID = nullptr;
		long nResult = EZGEM_GetCarrierList(pGEM, nIndex, &bstrCarrierID, &bstrLocID);
		if (SUCCEEDED(nResult))
		{
			if (bstrCarrierID)
			{
				strCarrierID = CString(bstrCarrierID);
				SysFreeString(bstrCarrierID);
			}
			else
			{
				strCarrierID.Empty();
			}
			if (bstrLocID)
			{
				strLocID = CString(bstrLocID);
				SysFreeString(bstrLocID);
			}
			else
			{
				strLocID.Empty();
			}
		}
		else
		{
			strCarrierID.Empty();
			strLocID.Empty();
		}
		return nResult;
	}

	long GetCarrierLocList(long nIndex, BSTR *psLocationID, BSTR *psCarrierID) { return EZGEM_GetCarrierLocList(pGEM, nIndex, psLocationID, psCarrierID); }
	long GetCarrierLocList(long nIndex, CString* psLocationID, CString* psCarrierID)
	{
		BSTR bstrLocationID = nullptr;
		BSTR bstrCarrierID = nullptr;
		long nResult = EZGEM_GetCarrierLocList(pGEM, nIndex, &bstrLocationID, &bstrCarrierID);
		if (SUCCEEDED(nResult))
		{
			if (psLocationID)
			{
				if (bstrLocationID)
				{
					*psLocationID = CString(bstrLocationID);
					SysFreeString(bstrLocationID);
				}
				else
				{
					psLocationID->Empty();
				}
			}
			if (psCarrierID)
			{
				if (bstrCarrierID)
				{
					*psCarrierID = CString(bstrCarrierID);
					SysFreeString(bstrCarrierID);
				}
				else
				{
					psCarrierID->Empty();
				}
			}
		}
		else
		{
			if (psLocationID) psLocationID->Empty();
			if (psCarrierID)  psCarrierID->Empty();
		}
		return nResult;
	}
	long GetCarrierLocList(long nIndex, CString& strLocationID, CString& strCarrierID)
	{
		BSTR bstrLocationID = nullptr;
		BSTR bstrCarrierID = nullptr;
		long nResult = EZGEM_GetCarrierLocList(pGEM, nIndex, &bstrLocationID, &bstrCarrierID);
		if (SUCCEEDED(nResult))
		{
			if (bstrLocationID)
			{
				strLocationID = CString(bstrLocationID);
				SysFreeString(bstrLocationID);
			}
			else
			{
				strLocationID.Empty();
			}
			if (bstrCarrierID)
			{
				strCarrierID = CString(bstrCarrierID);
				SysFreeString(bstrCarrierID);
			}
			else
			{
				strCarrierID.Empty();
			}
		}
		else
		{
			strLocationID.Empty();
			strCarrierID.Empty();
		}
		return nResult;
	}

	// PJM
	// override code for UNICODE
	long GetPrJobCarrier(CString szPrJobID, int nIndex, BSTR* pstrCarrierID, BSTR* pstrSlotList)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobCarrier(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nIndex, pstrCarrierID, pstrSlotList);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobCarrier(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nIndex, pstrCarrierID, pstrSlotList);
#endif
		return lAck;
	}
	long GetPrJobCarrier(CString szPrJobID, int nIndex, CString* pstrCarrierID, CString* pstrSlotList) 
	{
		BSTR bstrCarrierID = nullptr;
		BSTR bstrSlotList = nullptr;

#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobCarrier(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nIndex, &bstrCarrierID, &bstrSlotList);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobCarrier(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nIndex, &bstrCarrierID, &bstrSlotList);
#endif

		if (SUCCEEDED(lAck)) 
		{
			if (bstrCarrierID != nullptr) 
			{
				*pstrCarrierID = CString(bstrCarrierID);
				::SysFreeString(bstrCarrierID);
			}
			else 
			{
				pstrCarrierID->Empty();
			}
			if (bstrSlotList != nullptr) 
			{
				*pstrSlotList = CString(bstrSlotList);
				::SysFreeString(bstrSlotList);
			}
			else 
			{
				pstrSlotList->Empty();
			}
		}
		else 
		{
			pstrCarrierID->Empty();
			pstrSlotList->Empty();
		}
		return lAck;
	}
	long GetPrJobCarrier(CString szPrJobID, int nIndex, CString& strCarrierID, CString& strSlotList) 
	{
		BSTR bstrCarrierID = nullptr;
		BSTR bstrSlotList = nullptr;

#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobCarrier(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nIndex, &bstrCarrierID, &bstrSlotList);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobCarrier(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nIndex, &bstrCarrierID, &bstrSlotList);
#endif

		if (SUCCEEDED(lAck)) 
		{
			if (bstrCarrierID != nullptr) 
			{
				strCarrierID = CString(bstrCarrierID);
				::SysFreeString(bstrCarrierID);
			}
			else 
			{
				strCarrierID.Empty();
			}

			if (bstrSlotList != nullptr) 
			{
				strSlotList = CString(bstrSlotList);
				::SysFreeString(bstrSlotList);
			}
			else 
			{
				strSlotList.Empty();
			}
		}
		else 
		{
			strCarrierID.Empty();
			strSlotList.Empty();
		}
		return lAck;
	}

	long GetPrJobParam(CString szPrJobID, int nIndex, BSTR* pstrParamName, BSTR* pstrParamVal)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobParam(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nIndex, pstrParamName, pstrParamVal);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobParam(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nIndex, pstrParamName, pstrParamVal);
#endif
		return lAck;
	}
	long GetPrJobParam(CString szPrJobID, int nIndex, CString* pstrParamName, CString* pstrParamVal) 
	{
		BSTR bstrParamName = nullptr;
		BSTR bstrParamVal = nullptr;

#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobParam(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nIndex, &bstrParamName, &bstrParamVal);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobParam(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nIndex, &bstrParamName, &bstrParamVal);
#endif

		if (SUCCEEDED(lAck)) 
		{
			if (bstrParamName != nullptr) 
			{
				*pstrParamName = CString(bstrParamName);
				::SysFreeString(bstrParamName);
			}
			else 
			{
				pstrParamName->Empty();
			}

			if (bstrParamVal != nullptr) 
			{
				*pstrParamVal = CString(bstrParamVal);
				::SysFreeString(bstrParamVal);
			}
			else 
			{
				pstrParamVal->Empty();
			}
		}
		else 
		{
			pstrParamName->Empty();
			pstrParamVal->Empty();
		}
		return lAck;
	}
	long GetPrJobParam(CString szPrJobID, int nIndex, CString& strParamName, CString& strParamVal) 
	{
		BSTR bstrParamName = nullptr;
		BSTR bstrParamVal = nullptr;

#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobParam(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nIndex, &bstrParamName, &bstrParamVal);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobParam(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nIndex, &bstrParamName, &bstrParamVal);
#endif

		if (SUCCEEDED(lAck)) 
		{
			if (bstrParamName != nullptr) 
			{
				strParamName = CString(bstrParamName);
				::SysFreeString(bstrParamName);
			}
			else 
			{
				strParamName.Empty();
			}
			if (bstrParamVal != nullptr) 
			{
				strParamVal = CString(bstrParamVal);
				::SysFreeString(bstrParamVal);
			}
			else 
			{
				strParamVal.Empty();
			}
		}
		else 
		{
			strParamName.Empty();
			strParamVal.Empty();
		}
		return lAck;
	}

	long GetPrJobRecipeMethod(CString strPrJobID, int *pnRecipeMethod)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(strPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobRecipeMethod(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, pnRecipeMethod);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobRecipeMethod(pGEM, (LPCTSTR)(LPSTR)strPrJobID.GetBuffer(), pnRecipeMethod);
#endif
		return lAck;
	}

	long SetPrJobErrorCode(long lMsgId, CString szPrJobID, int nErrorCode, CString szErrorText)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		char* pszErrorText = SetWCharToChar(szErrorText.GetBuffer());
		long lAck = EZGEM_SetPrJobErrorCode(pGEM, lMsgId, (LPCTSTR)(LPSTR)pszPrJobID, nErrorCode, (LPCTSTR)(LPSTR)pszErrorText);
		free(pszPrJobID);
		free(pszErrorText);
#else
		long lAck = EZGEM_SetPrJobErrorCode(pGEM, lMsgId, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nErrorCode, (LPCTSTR)(LPSTR)szErrorText.GetBuffer());
#endif
		return lAck;
	}

	long GetPrJobInfo(CString szPrJobID, BSTR* pstrPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobInfo(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, pstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobInfo(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), pstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
#endif
		return lAck;
	}
	long GetPrJobInfo(CString szPrJobID, CString* pstrPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
		BSTR bstrPPID = nullptr;
		long lAck = -1;
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		lAck = EZGEM_GetPrJobInfo(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		free(pszPrJobID);
#else
		lAck = EZGEM_GetPrJobInfo(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
#endif
		if (pstrPPID)
		{
			if (SUCCEEDED(lAck))
			{
				*pstrPPID = CString(bstrPPID);
				SysFreeString(bstrPPID);
			}
			else
			{
				pstrPPID->Empty();
			}
		}
		return lAck;
	}
	long GetPrJobInfo(CString szPrJobID, CString& strPPID, int* pnCarrierCount, int* pnAutoStart, int* pnParamCount)
	{
		BSTR bstrPPID = nullptr;
		long lAck = -1;
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		lAck = EZGEM_GetPrJobInfo(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
		free(pszPrJobID);
#else
		lAck = EZGEM_GetPrJobInfo(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), &bstrPPID, pnCarrierCount, pnAutoStart, pnParamCount);
#endif
		if (SUCCEEDED(lAck))
		{
			strPPID = CString(bstrPPID);
			SysFreeString(bstrPPID);
		}
		else
		{
			strPPID.Empty();
		}
		return lAck;
	}

	long DeletePrJob(CString szPrJobID)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_DeletePrJob(pGEM, (LPCTSTR)(LPSTR)pszPrJobID);
		free(pszPrJobID);
#else
		long lAck = EZGEM_DeletePrJob(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer());
#endif
		return lAck;
	}

	long GetPrJobState(CString szPrJobID, int* pnPrJobState)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobState(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, pnPrJobState);
		free(pszPrJobID);
#else
		long lAck = EZGEM_GetPrJobState(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), pnPrJobState);
#endif
		return lAck;
	}

	long SetPrJobState(CString szPrJobID, int nPrJobState)
	{
#ifdef UNICODE
		char* pszPrJobID = SetWCharToChar(szPrJobID.GetBuffer());
		long lAck = EZGEM_SetPrJobState(pGEM, (LPCTSTR)(LPSTR)pszPrJobID, nPrJobState);
		free(pszPrJobID);
#else
		long lAck = EZGEM_SetPrJobState(pGEM, (LPCTSTR)(LPSTR)szPrJobID.GetBuffer(), nPrJobState);
#endif
		return lAck;
	}

	long CreatePrJob(CString sPrJobID, int nAutoStart, CString sCarrierList, CString sSlotList, CString sPPID)
	{
#ifdef UNICODE
		char* psPrJobID = SetWCharToChar(sPrJobID.GetBuffer());
		char* psCarrierList = SetWCharToChar(sCarrierList.GetBuffer());
		char* psSlotList = SetWCharToChar(sSlotList.GetBuffer());
		char* psPPID = SetWCharToChar(sPPID.GetBuffer());

		long lAck = EZGEM_CreatePrJob(pGEM, (LPCTSTR)(LPSTR)psPrJobID, nAutoStart, (LPCTSTR)(LPSTR)psCarrierList, (LPCTSTR)(LPSTR)psSlotList, (LPCTSTR)(LPSTR)psPPID);

		free(psPrJobID);
		free(psCarrierList);
		free(psSlotList);
		free(psPPID);
#else
		long lAck = EZGEM_CreatePrJob(pGEM, (LPCTSTR)(LPSTR)sPrJobID.GetBuffer(), nAutoStart, (LPCTSTR)(LPSTR)sCarrierList.GetBuffer(), (LPCTSTR)(LPSTR)sSlotList.GetBuffer(), (LPCTSTR)(LPSTR)sPPID.GetBuffer());
#endif
		return lAck;
	}

	long CreatePrJob(CString sPrJobID, int nAutoStart, CString sSubstrateList, CString sPPID)
	{
#ifdef UNICODE
		char* psPrJobID = SetWCharToChar(sPrJobID.GetBuffer());
		char* psSubstrateList = SetWCharToChar(sSubstrateList.GetBuffer());
		char* psPPID = SetWCharToChar(sPPID.GetBuffer());

		long lAck = EZGEM_CreatePrJobSubst(pGEM, (LPCTSTR)(LPSTR)psPrJobID, nAutoStart, (LPCTSTR)(LPSTR)psSubstrateList, (LPCTSTR)(LPSTR)psPPID);
		free(psPrJobID);
		free(psSubstrateList);
		free(psPPID);
#else
		long lAck = EZGEM_CreatePrJobSubst(pGEM, (LPCTSTR)(LPSTR)sPrJobID.GetBuffer(), nAutoStart, (LPCTSTR)(LPSTR)sSubstrateList.GetBuffer(), (LPCTSTR)(LPSTR)sPPID.GetBuffer());
#endif
		return lAck;
	}

	long GetPrJobMaterialFormatCode(CString sPrJobID)
	{
#ifdef UNICODE
		char* psPrJobID = SetWCharToChar(sPrJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobMaterialFormatCode(pGEM, (LPCTSTR)(LPSTR)psPrJobID);
		free(psPrJobID);
#else
		long lAck = EZGEM_GetPrJobMaterialFormatCode(pGEM, (LPCTSTR)(LPSTR)sPrJobID.GetBuffer());
#endif
		return lAck;
	}

	// CJM
	// override code for UNICODE
	long GetCtrlJobInfo(CString szCtrlJobID, int* pnPrJobCount, int* pnAutoStart)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_GetCtrlJobInfo(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, pnPrJobCount, pnAutoStart);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_GetCtrlJobInfo(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), pnPrJobCount, pnAutoStart);
#endif
		return lAck;
	}

	long GetCtrlJobMtrlOutMapCount(CString szCtrlJobID, int* pnMtrlOutMapCount)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_GetCtrlJobMtrlOutMapCount(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, pnMtrlOutMapCount);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_GetCtrlJobMtrlOutMapCount(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), pnMtrlOutMapCount);
#endif
		return lAck;
	}

	long GetCtrlJobMtrlOutInfo(CString szCtrlJobID, int nMapIndex, BSTR* pstrSrcCarrier, BSTR* pstrSrcSlotList, BSTR* pstrDestCarrier, BSTR* pstrDestSlotList)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_GetCtrlJobMtrlOutInfo(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nMapIndex, pstrSrcCarrier, pstrSrcSlotList, pstrDestCarrier, pstrDestSlotList);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_GetCtrlJobMtrlOutInfo(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nMapIndex, pstrSrcCarrier, pstrSrcSlotList, pstrDestCarrier, pstrDestSlotList);
#endif
		return lAck;
	}
	long GetCtrlJobMtrlOutInfo(CString szCtrlJobID, int nMapIndex,CString* pstrSrcCarrier, CString* pstrSrcSlotList,CString* pstrDestCarrier, CString* pstrDestSlotList)
	{
		BSTR bstrSrcCarrier = nullptr;
		BSTR bstrSrcSlotList = nullptr;
		BSTR bstrDestCarrier = nullptr;
		BSTR bstrDestSlotList = nullptr;
		long lAck = -1;
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		lAck = EZGEM_GetCtrlJobMtrlOutInfo(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nMapIndex,&bstrSrcCarrier, &bstrSrcSlotList, &bstrDestCarrier, &bstrDestSlotList);
		free(pszCtrlJobID);
#else
		lAck = EZGEM_GetCtrlJobMtrlOutInfo(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nMapIndex,&bstrSrcCarrier, &bstrSrcSlotList, &bstrDestCarrier, &bstrDestSlotList);
#endif
		if (SUCCEEDED(lAck))
		{
			if (pstrSrcCarrier && bstrSrcCarrier) 
			{
				*pstrSrcCarrier = CString(bstrSrcCarrier);
				SysFreeString(bstrSrcCarrier);
			}
			if (pstrSrcSlotList && bstrSrcSlotList) 
			{
				*pstrSrcSlotList = CString(bstrSrcSlotList);
				SysFreeString(bstrSrcSlotList);
			}
			if (pstrDestCarrier && bstrDestCarrier) 
			{
				*pstrDestCarrier = CString(bstrDestCarrier);
				SysFreeString(bstrDestCarrier);
			}
			if (pstrDestSlotList && bstrDestSlotList) 
			{
				*pstrDestSlotList = CString(bstrDestSlotList);
				SysFreeString(bstrDestSlotList);
			}
		}
		else
		{
			if (pstrSrcCarrier) pstrSrcCarrier->Empty();
			if (pstrSrcSlotList) pstrSrcSlotList->Empty();
			if (pstrDestCarrier) pstrDestCarrier->Empty();
			if (pstrDestSlotList) pstrDestSlotList->Empty();
		}
		return lAck;
	}
	long GetCtrlJobMtrlOutInfo(CString szCtrlJobID, int nMapIndex,CString& strSrcCarrier, CString& strSrcSlotList,CString& strDestCarrier, CString& strDestSlotList)
	{
		BSTR bstrSrcCarrier = nullptr;
		BSTR bstrSrcSlotList = nullptr;
		BSTR bstrDestCarrier = nullptr;
		BSTR bstrDestSlotList = nullptr;
		long lAck = -1;
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		lAck = EZGEM_GetCtrlJobMtrlOutInfo(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nMapIndex,&bstrSrcCarrier, &bstrSrcSlotList, &bstrDestCarrier, &bstrDestSlotList);
		free(pszCtrlJobID);
#else
		lAck = EZGEM_GetCtrlJobMtrlOutInfo(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nMapIndex,&bstrSrcCarrier, &bstrSrcSlotList, &bstrDestCarrier, &bstrDestSlotList);
#endif
		if (SUCCEEDED(lAck))
		{
			strSrcCarrier = bstrSrcCarrier ? CString(bstrSrcCarrier) : _T("");
			strSrcSlotList = bstrSrcSlotList ? CString(bstrSrcSlotList) : _T("");
			strDestCarrier = bstrDestCarrier ? CString(bstrDestCarrier) : _T("");
			strDestSlotList = bstrDestSlotList ? CString(bstrDestSlotList) : _T("");
		}
		else
		{
			strSrcCarrier.Empty();
			strSrcSlotList.Empty();
			strDestCarrier.Empty();
			strDestSlotList.Empty();
		}
		if (bstrSrcCarrier) SysFreeString(bstrSrcCarrier);
		if (bstrSrcSlotList) SysFreeString(bstrSrcSlotList);
		if (bstrDestCarrier) SysFreeString(bstrDestCarrier);
		if (bstrDestSlotList) SysFreeString(bstrDestSlotList);
		return lAck;
	}

	long GetPrJobInCtrlJob(CString szCtrlJobID, int nIndex, BSTR* pstrPrJobID)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_GetPrJobInCtrlJob(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nIndex, pstrPrJobID);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_GetPrJobInCtrlJob(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nIndex, pstrPrJobID);
#endif
		return lAck;
	}
	long GetPrJobInCtrlJob(CString szCtrlJobID, int nIndex, CString* pstrPrJobID)
	{
		BSTR bstrPrJobID = nullptr;
		long lAck = -1;
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		lAck = EZGEM_GetPrJobInCtrlJob(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nIndex, &bstrPrJobID);
		free(pszCtrlJobID);
#else
		lAck = EZGEM_GetPrJobInCtrlJob(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nIndex, &bstrPrJobID);
#endif
		if (SUCCEEDED(lAck))
		{
			if (pstrPrJobID)
				*pstrPrJobID = CString(bstrPrJobID);
			SysFreeString(bstrPrJobID);
		}
		else if (pstrPrJobID)
		{
			pstrPrJobID->Empty();
		}
		return lAck;
	}
	long GetPrJobInCtrlJob(CString szCtrlJobID, int nIndex, CString& strPrJobID)
	{
		BSTR bstrPrJobID = nullptr;
		long lAck = -1;
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		lAck = EZGEM_GetPrJobInCtrlJob(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nIndex, &bstrPrJobID);
		free(pszCtrlJobID);
#else
		lAck = EZGEM_GetPrJobInCtrlJob(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nIndex, &bstrPrJobID);
#endif
		if (SUCCEEDED(lAck))
		{
			strPrJobID = CString(bstrPrJobID);
			SysFreeString(bstrPrJobID);
		}
		else
		{
			strPrJobID.Empty();
		}
		return lAck;
	}

	long DeleteCtrlJob(CString szCtrlJobID)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_DeleteCtrlJob(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_DeleteCtrlJob(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer());
#endif
		return lAck;
	}

	long SetCtrlJobState(CString szCtrlJobID, int nState)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_SetCtrlJobState(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, nState);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_SetCtrlJobState(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), nState);
#endif
		return lAck;
	}

	long GetCtrlJobState(CString szCtrlJobID, int* pnState)
	{
#ifdef UNICODE
		char* pszCtrlJobID = SetWCharToChar(szCtrlJobID.GetBuffer());
		long lAck = EZGEM_GetCtrlJobState(pGEM, (LPCTSTR)(LPSTR)pszCtrlJobID, pnState);
		free(pszCtrlJobID);
#else
		long lAck = EZGEM_GetCtrlJobState(pGEM, (LPCTSTR)(LPSTR)szCtrlJobID.GetBuffer(), pnState);
#endif
		return lAck;
	}

	long CreateCtrlJob(CString sCtrlJobID, CString sPrJobList, int nAutoStat)
	{
#ifdef UNICODE
		char* psCtrlJobID = SetWCharToChar(sCtrlJobID.GetBuffer());
		char* psPrJobList = SetWCharToChar(sPrJobList.GetBuffer());
		long lAck = EZGEM_CreateCtrlJob(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, (LPCTSTR)(LPSTR)psPrJobList, nAutoStat);
		free(psCtrlJobID);
		free(psPrJobList);
#else
		long lAck = EZGEM_CreateCtrlJob(pGEM, (LPCTSTR)(LPSTR)sCtrlJobID.GetBuffer(), (LPCTSTR)(LPSTR)sPrJobList.GetBuffer(), nAutoStat);
#endif
		return lAck;
	}

	long AddCtrlJobCarrierInputSpec(CString strCtrlJobID, CString strCarrierID)
	{ 
#ifdef UNICODE
		char* psCtrlJobID = SetWCharToChar(strCtrlJobID.GetBuffer());
		char* psCarrierID = SetWCharToChar(strCarrierID.GetBuffer());
		long lAck = EZGEM_AddCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, (LPCTSTR)(LPSTR)psCarrierID);
		free(psCtrlJobID);
		free(psCarrierID);
#else
		long lAck = EZGEM_AddCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)strCtrlJobID.GetBuffer(), (LPCTSTR)(LPSTR)strCarrierID.GetBuffer());
#endif
		return lAck;
	}

	long AddCtrlJobMtrlOutSpec(CString strCtrlJobID, CString strSrcCarrierID, CString strSrcSlotList, CString strDestCarrierID, CString strDestSlotList) 
	{
#ifdef UNICODE
		char* psCtrlJobID = SetWCharToChar(strCtrlJobID.GetBuffer());
		char* psSrcCarrierID = SetWCharToChar(strSrcCarrierID.GetBuffer());
		char* psSrcSlotList = SetWCharToChar(strSrcSlotList.GetBuffer());
		char* psDestCarrierID = SetWCharToChar(strDestCarrierID.GetBuffer());
		char* psDestSlotList = SetWCharToChar(strDestSlotList.GetBuffer());
		long lAck = EZGEM_AddCtrlJobMtrlOutSpec(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, (LPCTSTR)(LPSTR)psSrcCarrierID, (LPCTSTR)(LPSTR)psSrcSlotList, (LPCTSTR)(LPSTR)psDestCarrierID, (LPCTSTR)(LPSTR)psDestSlotList);
		free(psCtrlJobID);
		free(psSrcSlotList);
		free(psDestCarrierID);
		free(psDestSlotList);
#else
		long lAck = EZGEM_AddCtrlJobMtrlOutSpec(pGEM, (LPCTSTR)(LPSTR)strCtrlJobID.GetBuffer(), (LPCTSTR)(LPSTR)strSrcCarrierID.GetBuffer() , (LPCTSTR)(LPSTR)strSrcSlotList.GetBuffer(), (LPCTSTR)(LPSTR)strDestCarrierID.GetBuffer(), (LPCTSTR)(LPSTR)strDestSlotList.GetBuffer());
#endif
		return lAck;
	}

	long GetCtrlJobCarrierInputSpec(CString strCtrlJobID, BSTR * pstrCarrierList) 
	{
#ifdef UNICODE
		char* psCtrlJobID = SetWCharToChar(strCtrlJobID.GetBuffer());
		long lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, pstrCarrierList);
		free(psCtrlJobID);
#else
		long lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)strCtrlJobID.GetBuffer(), pstrCarrierList);
#endif
		return lAck;
	}
	long GetCtrlJobCarrierInputSpec(CString strCtrlJobID, CStringArray* pCarrierList) 
	{
		BSTR bstrCarrierList = nullptr;
		long lAck = -1;
#ifdef UNICODE
		// CString ¡æ char* º¯È¯
		char* psCtrlJobID = SetWCharToChar(strCtrlJobID.GetBuffer());
		lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, &bstrCarrierList);
		free(psCtrlJobID); // µ¿Àû ÇÒ´ç ÇØÁ¦
		if (SUCCEEDED(lAck))
		{
			CString strCarrierList(bstrCarrierList);
			SysFreeString(bstrCarrierList);

			int pos = 0;
			CString token = strCarrierList.Tokenize(_T(","), pos);
			while (!token.IsEmpty())
			{
				pCarrierList->Add(token);
				token = strCarrierList.Tokenize(_T(","), pos);
			}
		}
#else
		// ANSI ¹öÀü
		lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCSTR)(LPCTSTR)strCtrlJobID, &bstrCarrierList);
		if (SUCCEEDED(lAck))
		{
			CString strCarrierList(bstrCarrierList);
			SysFreeString(bstrCarrierList);

			int pos = 0;
			CString token = strCarrierList.Tokenize(",", pos);
			while (!token.IsEmpty())
			{
				pCarrierList->Add(token);
				token = strCarrierList.Tokenize(",", pos);
			}
		}
#endif
		return lAck;
	}
	long GetCtrlJobCarrierInputSpec(CString strCtrlJobID, CStringArray& carrierList)
	{
		BSTR bstrCarrierList = nullptr;
		long lAck = -1;
#ifdef UNICODE
		// CString ¡æ char* º¯È¯
		char* psCtrlJobID = SetWCharToChar(strCtrlJobID.GetBuffer());
		lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, &bstrCarrierList);
		free(psCtrlJobID);
		if (SUCCEEDED(lAck))
		{
			CString strCarrierList(bstrCarrierList);
			SysFreeString(bstrCarrierList);
			int pos = 0;
			CString token = strCarrierList.Tokenize(_T(","), pos);
			while (!token.IsEmpty())
			{
				carrierList.Add(token);
				token = strCarrierList.Tokenize(_T(","), pos);
			}
		}
#else
		// ANSI ¹öÀü
		lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCSTR)(LPCTSTR)strCtrlJobID, &bstrCarrierList);
		if (SUCCEEDED(lAck))
		{
			CString strCarrierList(bstrCarrierList);
			SysFreeString(bstrCarrierList);

			int pos = 0;
			CString token = strCarrierList.Tokenize(",", pos);
			while (!token.IsEmpty())
			{
				carrierList.Add(token);
				token = strCarrierList.Tokenize(",", pos);
			}
		}
#endif
		return lAck;
	}
	long GetCtrlJobCarrierInputSpec(CString strCtrlJobID, std::vector<CString>& carrierList)
	{
		BSTR bstrCarrierList = nullptr;
		long lAck = -1;
#ifdef UNICODE
		// CString ¡æ char* º¯È¯
		char* psCtrlJobID = SetWCharToChar(strCtrlJobID.GetBuffer());
		lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCTSTR)(LPSTR)psCtrlJobID, &bstrCarrierList);
		free(psCtrlJobID); // µ¿Àû ÇÒ´ç ÇØÁ¦

		if (SUCCEEDED(lAck))
		{
			CString strCarrierList(bstrCarrierList);
			SysFreeString(bstrCarrierList);

			int pos = 0;
			CString token = strCarrierList.Tokenize(_T(","), pos);
			while (!token.IsEmpty())
			{
				carrierList.push_back(token);
				token = strCarrierList.Tokenize(_T(","), pos);
			}
		}
#else
		// ANSI ¹öÀü
		lAck = EZGEM_GetCtrlJobCarrierInputSpec(pGEM, (LPCSTR)(LPCTSTR)strCtrlJobID, &bstrCarrierList);
		if (SUCCEEDED(lAck))
		{
			CString strCarrierList(bstrCarrierList);
			SysFreeString(bstrCarrierList);

			int pos = 0;
			CString token = strCarrierList.Tokenize(",", pos);
			while (!token.IsEmpty())
			{
				carrierList.push_back(token);
				token = strCarrierList.Tokenize(",", pos);
			}
		}
#endif
		return lAck;
	}


	// STS
	long CreateSubstLoc(CString sLocID)
	{ 
#ifdef UNICODE
		char* psLocID = SetWCharToChar(sLocID.GetBuffer());
		
		long lAck = EZGEM_CreateSubstLoc(pGEM, (LPCTSTR)(LPSTR)psLocID);
		free(psLocID);
#else
		long lAck = EZGEM_CreateSubstLoc(pGEM, (LPCTSTR)(LPSTR)sLocID.GetBuffer());
#endif

		return lAck;
	}

	long CreateSubstBatchLoc(CString sBatchLocID)
	{
#ifdef UNICODE
		char* psBatchLocID = SetWCharToChar(sBatchLocID.GetBuffer());

		long lAck = EZGEM_CreateSubstBatchLoc(pGEM, (LPCTSTR)(LPSTR)psBatchLocID);
		free(psBatchLocID);
#else
		long lAck = EZGEM_CreateSubstBatchLoc(pGEM, (LPCTSTR)(LPSTR)sBatchLocID.GetBuffer());
#endif
		return lAck;
	}

	long CreateSubstrate(CString sSubstID)
	{
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());

		long lAck = EZGEM_CreateSubstrate(pGEM, (LPCTSTR)(LPSTR)psSubstID);
		free(psSubstID);
#else
		long lAck = EZGEM_CreateSubstrate(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer());
#endif

		return lAck;

	}

	long GetSubstrateState(CString sSubstID, int* pnTranState, int* pnProcState, int* pnReadState)
	{ 
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());

		long lAck = EZGEM_GetSubstrateState(pGEM, (LPCTSTR)(LPSTR)psSubstID, pnTranState, pnProcState, pnReadState);
		free(psSubstID);
#else
		long lAck = EZGEM_GetSubstrateState(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer(), pnTranState, pnProcState, pnReadState);
#endif

		return lAck;
	}

	long DeleteSubstrate(CString sSubstID)
	{
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());

		long lAck = EZGEM_DeleteSubstrate(pGEM, (LPCTSTR)(LPSTR)psSubstID);
		free(psSubstID);
#else
		long lAck = EZGEM_DeleteSubstrate(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer());
#endif
		return lAck;
	}

	long SetSubstrateMove(CString sSubstID, CString sToLocID, int nTransferState) 
	{ 
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());
		char* psToLocID = SetWCharToChar(sToLocID.GetBuffer());

		long lAck = EZGEM_SetSubstrateMove(pGEM, (LPCTSTR)(LPSTR)psSubstID, (LPCTSTR)(LPSTR)psToLocID, nTransferState);
		free(psSubstID);
		free(psToLocID);
#else
		long lAck = EZGEM_SetSubstrateMove(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer(), (LPCTSTR)(LPSTR)sToLocID.GetBuffer(), nTransferState);
#endif
		return lAck;
	}

	long SetSubstTranState(CString sSubstID, int nTranState) 
	{ 
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());

		long lAck = EZGEM_SetSubstTranState(pGEM, (LPCTSTR)(LPSTR)psSubstID, nTranState);
		free(psSubstID);
#else
		long lAck = EZGEM_SetSubstTranState(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer(), nTranState);
#endif
		return lAck;
	}

	long SetSubstProcState(CString sSubstID, int nProcState) 
	{ 
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());

		long lAck = EZGEM_SetSubstProcState(pGEM, (LPCTSTR)(LPSTR)psSubstID, nProcState);
		free(psSubstID);
#else
		long lAck = EZGEM_SetSubstProcState(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer(), nProcState);
#endif
		return lAck;
	}

	long SetSubstReadState(CString sSubstID, int nReadState) 
	{ 
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());

		long lAck = EZGEM_SetSubstReadState(pGEM, (LPCTSTR)(LPSTR)psSubstID, nReadState);
		free(psSubstID);
#else
		long lAck = EZGEM_SetSubstReadState(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer(), nReadState);
#endif
		return lAck;
	}

	long SetSubstIdRead(CString sSubstID, CString sReadID, int nReadResult) 
	{ 
#ifdef UNICODE
		char* psSubstID = SetWCharToChar(sSubstID.GetBuffer());
		char* psReadID = SetWCharToChar(sReadID.GetBuffer());

		long lAck = EZGEM_SetSubstIDRead(pGEM, (LPCTSTR)(LPSTR)psSubstID, (LPCTSTR)(LPSTR)psReadID, nReadResult);
		free(psSubstID);
		free(psReadID);
#else
		long lAck = EZGEM_SetSubstIDRead(pGEM, (LPCTSTR)(LPSTR)sSubstID.GetBuffer(), (LPCTSTR)(LPSTR)sReadID.GetBuffer(), nReadResult);
#endif

		return lAck; 
	}

	long ReplySubstAction(long lMsgId, int nRetCode, int nErrCode, CString strErrText) 
	{ 
#ifdef UNICODE
		char *pszErrText = SetWCharToChar(strErrText.GetBuffer());
		long nResult = EZGEM_ReplySubstAction(pGEM, lMsgId, nRetCode, nErrCode, (LPCTSTR)(LPSTR)pszErrText);
		free(pszErrText);
#else
		long nResult = EZGEM_ReplySubstAction(pGEM, lMsgId, nRetCode, nErrCode, (LPCTSTR)(LPSTR)strErrText.GetBuffer());
#endif
		return nResult;
	}

	long SetSubstLocState(CString strLocID, int nLocState)
	{
#ifdef UNICODE
		char *pszLocID = SetWCharToChar(strLocID.GetBuffer());
		long nResult = EZGEM_SetSubstLocState(pGEM, (LPCTSTR)(LPSTR)pszLocID, nLocState);
		free(pszLocID);
#else
		long nResult = EZGEM_SetSubstLocState(pGEM, (LPCTSTR)(LPSTR)strLocID.GetBuffer(), nLocState);
#endif
		return nResult;
	}

	// OSS
	long GetAttrName(CString strObjType, BSTR *psAttrNameList) 
	{ 
#ifdef UNICODE
		char *pszObjType = SetWCharToChar(strObjType.GetBuffer());
		long nResult = EZGEM_GetAttrName(pGEM, (LPCTSTR)(LPSTR)pszObjType, psAttrNameList);
		free(pszObjType);
#else
		long nResult = EZGEM_GetAttrName(pGEM, (LPCTSTR)(LPSTR)strObjType.GetBuffer(), psAttrNameList);
#endif
		return nResult;
	}
	long GetAttrName(CString strObjType, CStringArray *pAttrNameList)
	{
		BSTR bstrNameList;
		long nResult = GetAttrName((LPCTSTR)(LPSTR)strObjType.GetBuffer(), &bstrNameList);
		if (nResult < 0) return nResult;

		CString strNameList(bstrNameList);
		int start = 0;
		int end = 0;

		while ((end = strNameList.Find(_T(','), start)) != -1)
		{
			CString attr = strNameList.Mid(start, end - start).Trim();
			pAttrNameList->Add(attr);
			start = end + 1;
		}
		// ¸¶Áö¸· Ç×¸ñ Ãß°¡
		CString lastAttr = strNameList.Mid(start).Trim();
		if (!lastAttr.IsEmpty())
			pAttrNameList->Add(lastAttr);
		return nResult;
	}
	long GetAttrName(CString strObjType, CStringArray& pAttrNameList)
	{
		BSTR bstrNameList;
		long nResult = GetAttrName((LPCTSTR)(LPSTR)strObjType.GetBuffer(), &bstrNameList);
		if (nResult < 0) return nResult;

		CString strNameList(bstrNameList);
		SysFreeString(bstrNameList);

		int start = 0;
		int end = 0;

		while ((end = strNameList.Find(_T(','), start)) != -1)
		{
			CString attr = strNameList.Mid(start, end - start).Trim();
			pAttrNameList.Add(attr);
			start = end + 1;
		}
		// ¸¶Áö¸· Ç×¸ñ
		CString lastAttr = strNameList.Mid(start).Trim();
		if (!lastAttr.IsEmpty())
			pAttrNameList.Add(lastAttr);

		return nResult;
	}
	long GetAttrName(CString strObjType, std::vector<CString>& attrNameList)
	{
		BSTR bstrNameList;
		long nResult = GetAttrName((LPCTSTR)(LPSTR)strObjType.GetBuffer(), &bstrNameList);
		if (nResult < 0) return nResult;

		CString strNameList(bstrNameList);
		SysFreeString(bstrNameList);  // ¸Þ¸ð¸® ÇØÁ¦

		int start = 0;
		int end = 0;

		while ((end = strNameList.Find(_T(','), start)) != -1)
		{
			CString attr = strNameList.Mid(start, end - start).Trim();
			attrNameList.push_back(attr);
			start = end + 1;
		}
		// ¸¶Áö¸· Ç×¸ñ
		CString lastAttr = strNameList.Mid(start).Trim();
		if (!lastAttr.IsEmpty())
			attrNameList.push_back(lastAttr);

		return nResult;
	}

	long GetAttrData(CString strObjType, CString strObjID, CString strAttrName, BSTR *psAttrData) 
	{ 
#ifdef UNICODE
		char *pszObjType = SetWCharToChar(strObjType.GetBuffer());
		char *pszObjID = SetWCharToChar(strObjID.GetBuffer());
		char *pszAttrName = SetWCharToChar(strAttrName.GetBuffer());
		long nResult = EZGEM_GetAttrData(pGEM, (LPCTSTR)(LPSTR)pszObjType, (LPCTSTR)(LPSTR)pszObjID, (LPCTSTR)(LPSTR)pszAttrName, psAttrData);
		free(pszObjType);
		free(pszObjID);
		free(pszAttrName);
#else
		long nResult = EZGEM_GetAttrData(pGEM, (LPCTSTR)(LPSTR)strObjType.GetBuffer(), (LPCTSTR)(LPSTR)strObjID.GetBuffer(), (LPCTSTR)(LPSTR)strAttrName.GetBuffer(), psAttrData);
#endif
		return nResult;
	}	
	long GetAttrData(CString strObjType, CString strObjID, CString strAttrName, CString* psAttrData)
	{
		BSTR bstrAttrData = nullptr;

#ifdef UNICODE
		char* pszObjType = SetWCharToChar(strObjType.GetBuffer());
		char* pszObjID = SetWCharToChar(strObjID.GetBuffer());
		char* pszAttrName = SetWCharToChar(strAttrName.GetBuffer());

		long nResult = EZGEM_GetAttrData(
			pGEM,
			(LPCTSTR)(LPSTR)pszObjType,
			(LPCTSTR)(LPSTR)pszObjID,
			(LPCTSTR)(LPSTR)pszAttrName,
			&bstrAttrData
		);

		free(pszObjType);
		free(pszObjID);
		free(pszAttrName);
#else
		long nResult = EZGEM_GetAttrData(
			pGEM,
			(LPCTSTR)(LPSTR)strObjType.GetBuffer(),
			(LPCTSTR)(LPSTR)strObjID.GetBuffer(),
			(LPCTSTR)(LPSTR)strAttrName.GetBuffer(),
			&bstrAttrData
		);
#endif
		if (SUCCEEDED(nResult) && bstrAttrData) 
		{
			*psAttrData = CString(bstrAttrData);
			::SysFreeString(bstrAttrData);
		}
		else 
		{
			psAttrData->Empty();
		}
		return nResult;
	}
	long GetAttrData(CString strObjType, CString strObjID, CString strAttrName, CString& sAttrData)
	{
		BSTR bstrAttrData = nullptr;

#ifdef UNICODE
		char* pszObjType = SetWCharToChar(strObjType.GetBuffer());
		char* pszObjID = SetWCharToChar(strObjID.GetBuffer());
		char* pszAttrName = SetWCharToChar(strAttrName.GetBuffer());

		long nResult = EZGEM_GetAttrData(
			pGEM,
			(LPCTSTR)(LPSTR)pszObjType,
			(LPCTSTR)(LPSTR)pszObjID,
			(LPCTSTR)(LPSTR)pszAttrName,
			&bstrAttrData
		);

		free(pszObjType);
		free(pszObjID);
		free(pszAttrName);
#else
		long nResult = EZGEM_GetAttrData(
			pGEM,
			(LPCTSTR)(LPSTR)strObjType.GetBuffer(),
			(LPCTSTR)(LPSTR)strObjID.GetBuffer(),
			(LPCTSTR)(LPSTR)strAttrName.GetBuffer(),
			&bstrAttrData
		);
#endif
		if (SUCCEEDED(nResult) && bstrAttrData) 
		{
			sAttrData = CString(bstrAttrData);
			::SysFreeString(bstrAttrData);
		}
		else 
		{
			sAttrData.Empty();
		}
		return nResult;
	}

	long GetAttrData(CString strObjType, CString strObjID, CString strAttrName, CStringArray *pAttrData)
	{
		BSTR bstrAttrData;
		long nResult = GetAttrData((LPCTSTR)(LPSTR)strObjType.GetBuffer(), (LPCTSTR)(LPSTR)strObjID.GetBuffer(), (LPCTSTR)(LPSTR)strAttrName.GetBuffer(), &bstrAttrData);
		if (nResult < 0) return nResult;
		CString strDataList(bstrAttrData); // BSTR ¡æ CString
		int start = 0;
		int end = 0;
		while ((end = strDataList.Find(_T(','), start)) != -1)
		{
			CString data = strDataList.Mid(start, end - start).Trim();
			pAttrData->Add(data);
			start = end + 1;
		}
		// ¸¶Áö¸· Ç×¸ñ Ãß°¡
		CString lastData = strDataList.Mid(start).Trim();
		if (!lastData.IsEmpty())
			pAttrData->Add(lastData);
		// nResult¸¸Å­ Ç×¸ñÀÌ ¾È Ã¡À¸¸é ºó ¹®ÀÚ¿­·Î Ã¤¿ò
		while (pAttrData->GetCount() < nResult)
			pAttrData->Add(_T(""));
		return nResult;
	}
	long GetAttrData(CString strObjType, CString strObjID, CString strAttrName, CStringArray& attrData)
	{
		BSTR bstrAttrData;
		long nResult = GetAttrData((LPCTSTR)(LPSTR)strObjType.GetBuffer(),(LPCTSTR)(LPSTR)strObjID.GetBuffer(),(LPCTSTR)(LPSTR)strAttrName.GetBuffer(),	&bstrAttrData);
		if (nResult < 0) return nResult;
		CString strDataList(bstrAttrData);
		SysFreeString(bstrAttrData);  // ¸Þ¸ð¸® ÇØÁ¦
		int start = 0, end = 0;
		while ((end = strDataList.Find(_T(','), start)) != -1)
		{
			CString data = strDataList.Mid(start, end - start).Trim();
			attrData.Add(data);
			start = end + 1;
		}
		CString lastData = strDataList.Mid(start).Trim();
		if (!lastData.IsEmpty())
			attrData.Add(lastData);
		// ºÎÁ·ÇÑ Ç×¸ñÀº ºó ¹®ÀÚ¿­·Î Ã¤¿ò
		while (attrData.GetCount() < nResult)
			attrData.Add(_T(""));
		return nResult;
	}
	long GetAttrData(CString strObjType, CString strObjID, CString strAttrName, std::vector<CString>& attrData)
	{
		BSTR bstrAttrData;
		long nResult = GetAttrData((LPCTSTR)(LPSTR)strObjType.GetBuffer(),
			(LPCTSTR)(LPSTR)strObjID.GetBuffer(),
			(LPCTSTR)(LPSTR)strAttrName.GetBuffer(),
			&bstrAttrData);

		if (nResult < 0) return nResult;

		CString strDataList(bstrAttrData);
		SysFreeString(bstrAttrData);  // BSTR ÇØÁ¦

		int start = 0, end = 0;
		while ((end = strDataList.Find(_T(','), start)) != -1)
		{
			CString data = strDataList.Mid(start, end - start).Trim();
			attrData.push_back(data);
			start = end + 1;
		}
		CString lastData = strDataList.Mid(start).Trim();
		if (!lastData.IsEmpty())
			attrData.push_back(lastData);

		// ºÎÁ·ÇÑ Ç×¸ñÀº ºó ¹®ÀÚ¿­·Î Ã¤¿ò
		while (attrData.size() < static_cast<size_t>(nResult))
			attrData.push_back(_T(""));

		return nResult;
	}

	long SetAttrData(CString strObjType, CString strObjID, CString strAttrName, CString strNewVal) 
	{ 
#ifdef UNICODE
		char *pszObjType = SetWCharToChar(strObjType.GetBuffer());
		char *pszObjID = SetWCharToChar(strObjID.GetBuffer());
		char *pszAttrName = SetWCharToChar(strAttrName.GetBuffer());
		char *pszNewVal = SetWCharToChar(strNewVal.GetBuffer());
		long nResult = EZGEM_SetAttrData(pGEM, (LPCTSTR)(LPSTR)pszObjType, (LPCTSTR)(LPSTR)pszObjID, (LPCTSTR)(LPSTR)pszAttrName, (LPCTSTR)(LPSTR)pszNewVal);
#else
		long nResult = EZGEM_SetAttrData(pGEM, (LPCTSTR)(LPSTR)strObjType.GetBuffer(), (LPCTSTR)(LPSTR)strObjID.GetBuffer(), (LPCTSTR)(LPSTR)strAttrName.GetBuffer(), (LPCTSTR)(LPSTR)strNewVal.GetBuffer());
#endif
		return nResult;
	}
	long GetObjectList(CString strObjType, BSTR *psObjList) 
	{ 
#ifdef UNICODE
		char *pszObjType = SetWCharToChar(strObjType.GetBuffer());
		long nResult = EZGEM_GetObjectList(pGEM, (LPCTSTR)(LPSTR)pszObjType, psObjList);
		free(pszObjType);
#else
		long nResult = EZGEM_GetObjectList(pGEM, (LPCTSTR)(LPSTR)strObjType.GetBuffer(), psObjList);
#endif
		return nResult;
	}
	long GetObjectList(CString strObjType, CStringArray *pObjList)
	{
		BSTR bstrObjList;
		long nResult = GetObjectList((LPCTSTR)(LPSTR)strObjType.GetBuffer(), &bstrObjList);
		if (nResult < 0) return nResult;

		CString strList(bstrObjList); // BSTR ¡æ CString
		int start = 0;
		int end = 0;
		while ((end = strList.Find(_T(','), start)) != -1)
		{
			CString obj = strList.Mid(start, end - start).Trim();
			pObjList->Add(obj);
			start = end + 1;
		}
		// ¸¶Áö¸· Ç×¸ñ Ãß°¡
		CString lastObj = strList.Mid(start).Trim();
		if (!lastObj.IsEmpty())
			pObjList->Add(lastObj);
		// ¿¹»ó °³¼ö(nResult)º¸´Ù ºÎÁ·ÇÏ¸é ºó Ç×¸ñ Ãß°¡
		while (pObjList->GetCount() < nResult)
			pObjList->Add(_T(""));
		return nResult;
	}
	long GetObjectList(CString strObjType, CStringArray& objList)
	{
		BSTR bstrObjList = nullptr;
		long nResult = GetObjectList((LPCTSTR)(LPSTR)strObjType.GetBuffer(), &bstrObjList);
		if (nResult < 0) return nResult;

		CString strList(bstrObjList);
		SysFreeString(bstrObjList);

		int start = 0, end = 0;
		while ((end = strList.Find(_T(','), start)) != -1)
		{
			CString obj = strList.Mid(start, end - start).Trim();
			objList.Add(obj);
			start = end + 1;
		}

		CString lastObj = strList.Mid(start).Trim();
		if (!lastObj.IsEmpty())
			objList.Add(lastObj);

		while (objList.GetCount() < nResult)
			objList.Add(_T(""));

		return nResult;
	}
	long GetObjectList(CString strObjType, std::vector<CString>& objList)
	{
		BSTR bstrObjList = nullptr;
		long nResult = GetObjectList((LPCTSTR)(LPSTR)strObjType.GetBuffer(), &bstrObjList);
		if (nResult < 0) return nResult;

		CString strList(bstrObjList);
		SysFreeString(bstrObjList);

		int start = 0, end = 0;
		while ((end = strList.Find(_T(','), start)) != -1)
		{
			CString obj = strList.Mid(start, end - start).Trim();
			objList.push_back(obj);
			start = end + 1;
		}

		CString lastObj = strList.Mid(start).Trim();
		if (!lastObj.IsEmpty())
			objList.push_back(lastObj);

		while (objList.size() < static_cast<size_t>(nResult))
			objList.push_back(_T(""));

		return nResult;
	}

	/////////////////////////////////////////////////////////////////////////////////////////////		
private:
		char* SetWCharToChar(TCHAR* strBuff)
		{
			char* pszValue = NULL;
#ifdef _UNICODE

			int len = WideCharToMultiByte(CP_ACP, 0, strBuff, -1, NULL, 0, NULL, NULL);
			pszValue = (char*)malloc(sizeof(char) * len + 1);
			WideCharToMultiByte(CP_ACP, 0, strBuff, -1, pszValue, len, NULL, NULL);
#else

#endif
			return pszValue;
		}
};
