// ImpLock.h : CImpLock 的声明
#pragma once
#include "resource.h" // 主符号
#include "MeromLock_i.h"
#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Windows CE 平台(如不提供完全 DCOM 支持的 Windows Mobile 平台)上无法正确支持单线程 COM 对象。定义 _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA 可强制 ATL 支持创建单线程 COM 对象实现并允许使用其单线程 COM 对象实现。rgs 文件中的线程模型已被设置为“Free”,原因是该模型是非 DCOM Windows CE 平台支持的唯一线程模型。"
#endif
using namespace ATL;
// CImpLock
class ATL_NO_VTABLE CImpLock :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CImpLock, &CLSID_ImpLock>,
public IDispatchImpl<IImpLock, &IID_IImpLock, &LIBID_MeromLockLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
CImpLock()
{
TCHAR chCurDir[MAX_PATH] = { 0 };
GetCurrentDirectory(MAX_PATH, chCurDir);
SetCurrentDirectory(_T("D:\\Project\\MLLock\\Release\\"));
hDll = LoadLibrary(_T("MF1_AnLock2009.dll")); //加载dll
SetCurrentDirectory(chCurDir);
DWORD ds = GetLastError();
SLOG_INFO("ds = %d\n", ds);
}
DECLARE_REGISTRY_RESOURCEID(IDR_IMPLOCK)
BEGIN_COM_MAP(CImpLock)
COM_INTERFACE_ENTRY(IImpLock)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
FreeLibrary(hDll); // 卸载dll
}
public:
STDMETHOD(Init)(BSTR* vaR);
STDMETHOD(Read)(VARIANT * roomNum, BSTR* vaR);
STDMETHOD(Write)(VARIANT roomNum, VARIANT startData, VARIANT endtData, VARIANT startTime, VARIANT endTime, BSTR* vaR);
private:
HINSTANCE hDll; //DLL句柄
};
OBJECT_ENTRY_AUTO(__uuidof(ImpLock), CImpLock)
// ImpLock.cpp : CImpLock 的实现
#include "stdafx.h"
#include <comdef.h>
#include <fstream>
#include <iostream>
#include "slog.h"
#include "HotelF.h"
#include "ImpLock.h"
#include "DataTime.h"
using namespace std;
// CImpLock::
//#pragma warning(disable : 4996)
STDMETHODIMP CImpLock::Init(BSTR* vaR)
{
int iR = 0;
char *pR = new char[4];
//_itoa(iR, pR, 10);
_itoa_s(iR, pR, 4, 10);
_bstr_t _bstr_CardInfor(pR);
BSTR bstrCardInfor = _bstr_CardInfor.copy(true);
*vaR = bstrCardInfor;
return S_OK;
}
STDMETHODIMP CImpLock::Read(VARIANT * roomNum, BSTR* vaR)
{
// TODO: 在此添加实现代码
if (hDll == nullptr)
{
SLOG_ERROR("dll加载失败");
return S_FALSE; //dll加载失败
}
int iCommID = 3;
int iCardType = 0;
unsigned char cMF_Area = 15;
char* pcR = nullptr;
ReadCardInfoFUN ReadCardInfoFun = (ReadCardInfoFUN)GetProcAddress(hDll, "ReadCardInfo");
if (ReadCardInfoFun == NULL)
{
SLOG_ERROR("动态调用ReadCardInfo 函数失败");
return S_FALSE;
}
pcR = ReadCardInfoFun(iCommID, iCardType, cMF_Area);
string strR(pcR);
string strRoomNum("");
DataTime::NewObject()->CalculateRoomNum(strR, strRoomNum);
VARIANT varoomNum;
VariantInit(&varoomNum);
varoomNum.vt = VT_BSTR;
_bstr_t bstr_roomNum(strRoomNum.c_str());
BSTR bstrroomNum = bstr_roomNum.copy(true);
varoomNum.bstrVal = bstrroomNum;
_bstr_t _bstr_ReadCardInfor(pcR);
BSTR bstr_ReadCardInfor = _bstr_ReadCardInfor.copy(true);
*vaR = bstr_ReadCardInfor;
//delete[]pcR; pcR = nullptr;
return S_OK;
}
STDMETHODIMP CImpLock::Write(VARIANT roomNum, VARIANT startData, VARIANT endtData, VARIANT startTime, VARIANT endTime, BSTR* vaR)
{
// TODO: 在此添加实现代码
if (hDll == nullptr)
{
SLOG_ERROR("dll加载失败");
return S_FALSE; //dll加载失败
}
int iCommID = 3;
int iCardType = 0;
int iOldKeyEnd = 1;
int iBAKKey = 0;
int iTSRight = 1;
unsigned int uiFloorCode = 0;
unsigned int uiFloorLayCode = 0;
unsigned int uiRoomCode = roomNum.intVal;
unsigned int uiiSubRoomCode = 0;
_bstr_t bstr_StartDate(startData.bstrVal);
_bstr_t bstr_EndDate(endtData.bstrVal);
_bstr_t bstr_startTime(startTime.bstrVal);
_bstr_t bstr_endTime(endTime.bstrVal);
char *pStartDate = bstr_StartDate;
char *pEndDate = bstr_EndDate;
char *pStartTime = bstr_startTime;
char *pEndTime = bstr_endTime;
char *pTemp = "18991230";
long lStartDatedayNum = DataTime::NewObject()->CalDataDayNum(pTemp, pStartDate);
long lEndDatedayNum = DataTime::NewObject()->CalDataDayNum(pTemp, pEndDate);
int iStartTime = 0;
DataTime::NewObject()->CalculateHHMMSS(pStartTime, &iStartTime);
int iEndTime = 0;
DataTime::NewObject()->CalculateHHMMSS(pEndTime, &iEndTime);
unsigned char cMF_Area = 15;
// SLOG_INFO("iCommID= %d", iCommID);
// SLOG_INFO("iCardType= %d", iCardType);
// SLOG_INFO("iOldKeyEnd= %d", iOldKeyEnd);
// SLOG_INFO("iBAKKey= %d", iBAKKey);
// SLOG_INFO("iTSRight= %d", iTSRight);
// SLOG_INFO("uiFloorCode= %d", uiFloorCode);
// SLOG_INFO("uiFloorLayCode= %d", uiFloorLayCode);
// SLOG_INFO("uiRoomCode= %d", uiRoomCode);
// SLOG_INFO("uiiSubRoomCode= %d", uiiSubRoomCode);
//SLOG_INFO("iStartDate= %d", iStartDate);
//SLOG_INFO("iStartTime= %d", iStartTime);
//SLOG_INFO("iEndDate= %d", iEndDate);
//SLOG_INFO("iEndTime= %d", iEndDate);
//SLOG_INFO("cMF_Area= %d", cMF_Area);
int iR = -11111;
WriteCardInfoFUN WriteCardInfoFun = (WriteCardInfoFUN)GetProcAddress(hDll, "WriteGuestCard");
if (WriteCardInfoFun == NULL)
{
SLOG_ERROR("动态调用WriteGuestCard 函数失败");
return S_FALSE;
}
iR = WriteCardInfoFun(iCommID, iCardType, iOldKeyEnd, iBAKKey, iTSRight, uiFloorCode, uiFloorLayCode, uiRoomCode, uiiSubRoomCode, lStartDatedayNum, iStartTime, lEndDatedayNum, iEndTime, cMF_Area);
char *pR = new char[4];
//_itoa(iR, pR, 10);
_itoa_s(iR, pR, 4, 10);
_bstr_t _bstr_WriteCardInfo(pR);
BSTR bstrWriteCardInfo = _bstr_WriteCardInfo.copy(true);
*vaR = bstrWriteCardInfo;
//SLOG_INFO("iR= %d", iR);
delete[]pR; pR = nullptr;
return S_OK;
}
// MeromLock.idl : MeromLock的 IDL 源
//
// 此文件将由 MIDL 工具处理以
// 产生类型库(MeromLock.tlb)和封送处理代码。
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(3B5EB060-2880-49CA-B3EE-ED757F292893),
dual,
nonextensible,
pointer_default(unique)
]
interface IImpLock : IDispatch{
[id(1)] HRESULT Init([out, retval] BSTR* vaR);
[id(2)] HRESULT Read([out] VARIANT* roomNum, [out, retval] BSTR* vaR);
[id(3)] HRESULT Write([in] VARIANT roomNum, [in] VARIANT startData, [in] VARIANT endtData, [in] VARIANT startTime, [in] VARIANT endTime, [out, retval] BSTR* vaR);
};
[
uuid(EB1A2A21-EEAD-469F-9E4A-B6E2CF1CC4E1),
version(1.0),
]
library MeromLockLib
{
importlib("stdole2.tlb");
[
uuid(A905666A-C5A8-444E-8148-A26F76915928)
]
coclass ImpLock
{
[default] interface IImpLock;
};
};