⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 creditverification.cpp

📁 Visual_C++[1].NET_Bible1 Visual_C++宝典书中的全部源码
💻 CPP
字号:
// 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, public ISomethingElse
{
private:
	enum CardType {Visa, MasterCard, Amex} m_type;
	long m_refCount;
public:
	CCreditVerification() : m_refCount(0) {}

	void Foo() { }

	HRESULT __stdcall QueryInterface(REFIID iid, void**pp)
	{
		if (NULL == pp)
			return E_INVALIDARG;
		*pp = NULL;

		if (iid == IID_IUnknown) 
			*pp = this;
		else if (iid == IID_ICreditVerification)
			*pp = static_cast<ICreditVerification*>(this);
		else if (iid == IID_ISomethingElse)
			*pp = static_cast<ISomethingElse*>(this);

		if (*pp)
		{
			AddRef();
			return S_OK;
		}
		return E_NOINTERFACE;

		return 0; 
	}

	ULONG __stdcall AddRef() { return ++m_refCount; }
	ULONG __stdcall 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;
}

⌨️ 快捷键说明

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