dmcwincpp.docx
《dmcwincpp.docx》由会员分享,可在线阅读,更多相关《dmcwincpp.docx(25页珍藏版)》请在冰豆网上搜索。
![dmcwincpp.docx](https://file1.bdocx.com/fileroot1/2023-1/10/9110b631-1f56-492b-9da8-9aa959755e2b/9110b631-1f56-492b-9da8-9aa959755e2b1.gif)
dmcwincpp
//IncludethisfileforMicrosoftVisualC++ifyouareusingpre-compiledheaders
#include"stdafx.h"
#include"dmcwin.h"
CDMCWin:
:
CDMCWin()
{
m_usController=0;
m_hWnd=0;
m_lThreadID=0;
m_bConnected=FALSE;
m_hDmc=-1;
m_lLastError=0;
#ifdefDMCMULTIPLETHREADS
InitializeCriticalSection(&m_CritSec);
#endif
}
CDMCWin:
:
CDMCWin(USHORTusController,HWNDhWnd,LONGlThreadID)
{
m_usController=usController;
m_hWnd=hWnd;
m_lThreadID=lThreadID;
m_bConnected=FALSE;
m_hDmc=-1;
m_lLastError=0;
#ifdefDMCMULTIPLETHREADS
InitializeCriticalSection(&m_CritSec);
#endif
if(m_usController>0&&m_usController<17)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
if(m_lThreadID)
m_lLastError=DMCOpen2(m_usController,m_lThreadID,&m_hDmc);
else
m_lLastError=DMCOpen(m_usController,m_hWnd,&m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
if(m_lLastError==0)
m_bConnected=TRUE;
else
m_hDmc=-1;
}
}
CDMCWin:
:
~CDMCWin()
{
if(m_hDmc!
=-1)
Close();
#ifdefDMCMULTIPLETHREADS
DeleteCriticalSection(&m_CritSec);
#endif
}
LONGCDMCWin:
:
Open()
{
m_lLastError=0;
if(m_bConnected)
returnm_lLastError;
if(m_usController>0&&m_usController<17)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
if(m_lThreadID)
m_lLastError=DMCOpen2(m_usController,m_lThreadID,&m_hDmc);
else
m_lLastError=DMCOpen(m_usController,m_hWnd,&m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
if(m_lLastError==0)
m_bConnected=TRUE;
else
m_hDmc=-1;
}
else
m_lLastError=DMCERROR_CONTROLLER;
returnm_lLastError;
}
LONGCDMCWin:
:
Open(USHORTusController,HWNDhWnd,LONGlThreadID)
{
m_usController=usController;
m_hWnd=hWnd;
m_lThreadID=lThreadID;
returnOpen();
}
HANDLEDMCCDMCWin:
:
GetHandle()
{
if(m_hDmc!
=-1)
returnm_hDmc;
if(m_usController>0&&m_usController<17)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCGetHandle(m_usController,&m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
if(m_lLastError==0)
returnm_hDmc;
}
return-1;
}
voidCDMCWin:
:
SethWnd(HWNDhWnd)
{
m_hWnd=hWnd;
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCChangeInterruptNotification(m_hDmc,(long)hWnd);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
};
voidCDMCWin:
:
SetThreadID(LONGlThreadID)
{
m_lThreadID=lThreadID;
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCChangeInterruptNotification(m_hDmc,(long)lThreadID);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
};
LONGCDMCWin:
:
Close()
{
m_lLastError=0;
if(m_hDmc!
=-1)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCClose(m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
m_hDmc=-1;
m_bConnected=FALSE;
returnm_lLastError;
}
LONGCDMCWin:
:
Command(constPSZpszCommand,PCHARpchResponse,ULONGcbResponse)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCCommand(m_hDmc,(PSZ)pszCommand,pchResponse,cbResponse);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
else
m_lLastError=DMCERROR_HANDLE;
returnm_lLastError;
}
LONGCDMCWin:
:
FastCommand(constPSZpszCommand)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCFastCommand(m_hDmc,(PSZ)pszCommand);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
else
m_lLastError=DMCERROR_HANDLE;
returnm_lLastError;
}
LONGCDMCWin:
:
BinaryCommand(PBYTEpbCommand,ULONGulCommandLength,PCHARpchResponse,ULONGcbResponse)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCBinaryCommand(m_hDmc,pbCommand,ulCommandLength,pchResponse,cbResponse);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
else
m_lLastError=DMCERROR_HANDLE;
returnm_lLastError;
}
LONGCDMCWin:
:
GetUnsolicitedResponse(PCHARpchResponse,ULONGcbResponse)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCGetUnsolicitedResponse(m_hDmc,pchResponse,cbResponse);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
else
m_lLastError=DMCERROR_HANDLE;
returnm_lLastError;
}
LONGCDMCWin:
:
GetAdditionalResponseLen()
{
LONGlLength;
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCGetAdditionalResponseLen(m_hDmc,(PULONG)&lLength);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
else
m_lLastError=DMCERROR_HANDLE;
if(m_lLastError!
=0)
lLength=0;
returnlLength;
}
LONGCDMCWin:
:
GetAdditionalResponse(PCHARpchResponse,ULONGcbResponse)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCGetAdditionalResponse(m_hDmc,pchResponse,cbResponse);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
else
m_lLastError=DMCERROR_HANDLE;
returnm_lLastError;
}
LONGCDMCWin:
:
GetErrorText(LONGlError,PCHARpchMessage,ULONGcbMessage)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCError(m_hDmc,lError,pchMessage,cbMessage);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
returnm_lLastError;
}
LONGCDMCWin:
:
Clear()
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCClear(m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
Reset()
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCReset(m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
MasterReset()
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCMasterReset(m_hDmc);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
GetVersion(PCHARpchVersion,ULONGcbVersion)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCVersion(m_hDmc,pchVersion,cbVersion);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
DownloadFile(constPSZpszFileName,constPSZpszLabel)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCDownloadFile(m_hDmc,(PSZ)pszFileName,(PSZ)pszLabel);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
DownloadFromBuffer(constPSZpszBuffer,constPSZpszLabel)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCDownloadFromBuffer(m_hDmc,(PSZ)pszBuffer,(PSZ)pszLabel);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
UploadFile(constPSZpszFileName)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCUploadFile(m_hDmc,(PSZ)pszFileName);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
UploadToBuffer(PCHARpchBuffer,ULONGcbBuffer)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCUploadToBuffer(m_hDmc,pchBuffer,cbBuffer);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
SendFile(constPSZpszFileName)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCSendFile(m_hDmc,(PSZ)pszFileName);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
SendBinaryFile(constPSZpszFileName)
{
if(m_bConnected)
{
#ifdefDMCMULTIPLETHREADS
EnterCriticalSection(&m_CritSec);
#endif
m_lLastError=DMCSendBinaryFile(m_hDmc,(PSZ)pszFileName);
#ifdefDMCMULTIPLETHREADS
LeaveCriticalSection(&m_CritSec);
#endif
}
returnm_lLastError;
}
LONGCDMCWin:
:
AsciiCommandToBinaryCommand(PSZpszAsciiCommand,ULONGulAsciiCommandLength,PBYTEpbBinaryResult,ULONGcbBinaryResult,ULONGFAR*pulBinaryResultLength)
{
m_lLastError=DMCCommand_AsciiToBinary(m_hDmc,pszAsciiCommand,ulAsciiCommandLength,pbBinaryResult,cbBinaryResult,pulBinaryResultLength);
returnm_lLastError;
}
LONGCDMCWin:
:
BinaryCommandToAsciiCommand(PBYTEpbBinaryCommand,ULONGulBinaryCommandLength,PSZpszAsciiResult,ULONGcbAsciiResult,ULONGFAR*pulAsciiResultLength)
{
m_lLastError=DMCCommand_BinaryToAscii(m_hDmc,pbBinaryCommand,ulBinaryCommandLength,pszAsciiResult,cbAsciiResult,pulAsciiResultLength);
returnm_lLastError;
}
LONGCDMCWin:
:
AsciiFileToBinaryFile(constPSZpszInputFileName,constPSZpszOutputFileName)
{
m_lLastError=DMCFil