creditverification.cpp

来自「Visual_C++[1].NET_Bible1 Visual_C++宝典书中」· C++ 代码 · 共 69 行

CPP
69
字号
// CreditVerification.cpp 
#include "stdafx.h"

#define _DLL
#include "creditverification.h"

BOOL APIENTRY DllMain(HANDLE hModule,
	DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}

class CCreditVerification : public ICreditVerification
{
private:
	enum CardType {Visa, MasterCard, Amex} m_type;
	long m_refCount;
public:
	CCreditVerification() : m_refCount(0) {}
	long QueryInterface(IID& iid, void** pp) { return 0; }

	long AddRef() { return ++m_refCount; }
	long Release() 
	{
		if (--m_refCount == 0) 
		{
			delete this;
			return 0;
		}
		return m_refCount;
	}

	void SetCardType(char* s)
	{
		if (0 == strcmp("Visa", s))
			m_type = Visa;
		else if (0 == strcmp("MasterCard", s))
			m_type = MasterCard;
		else m_type = Amex;
	}
	bool VerifyCardNumber(long n) 
	{
		if (m_type == Visa)
			return (n % 2);
		else if (m_type == MasterCard)
			return (n % 3);
		else if (m_type == Amex)
			return (n % 5);
		else return false;
	}
};

DLLSPEC ICreditVerification* GetCreditVerificationObject()
{
	ICreditVerification* p = new CCreditVerification;
	p->AddRef();
	return p;
}


/*
DLLSPEC void DeleteCreditVerificationObject(ICreditVerification* p)
{
	delete p;
}
	void DeleteMe() { delete this; }
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?