Developing COM Components using VC-ATL(3-5) (轉)
:namespace prefix = o ns = "urn:schemas--com::office" />
4. 編寫實現功能的程式碼
ValidateCard.cpp清單
// ValidateCard.cpp : Implementation of CValidateCard
#include "stdafx.h"
#include "ValidateCreditCardServer.h"
#include "ValidateCard.h"
/////////////////////////////////////////////////////////////////////////////
// CValidateCard
STDMETHODIMP CValidateCard::ValidateCreditCard(BSTR bstrCCNo, BSTR bstrCCType, long *val)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
CString strType(bstrCCType);
strType.MakeUpper();
if(strType.Compare("VISA")==0)
bstrCCType=SysAllocString(OLESTR("V"));
else if(strType.Compare("MASTER")==0)
bstrCCType=SysAllocString(OLESTR("M"));
else if(strType.Compare("AMERICAN")==0)
bstrCCType=SysAllocString(OLESTR("A"));
else
{
*val=0;
return S_FALSE;
}
if((PrefixCheck(bstrCCNo,bstrCCType)==S_OK) && (LengthCheck(bstrCCNo,bstrCCType)==S_OK) && (LuhnCheck(bstrCCNo,bstrCCType)==S_OK))
{
*val=1;
return S_OK;
}
else
{
*val=0;
return S_FALSE;
}
return S_FALSE;
}
STDMETHODIMP CValidateCard::LuhnCheck(BSTR bstrCCNo, BSTR bstrCCType)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
CString strobj(bstrCCNo);
CString strReverse,strFinal;
int iNum,iSum;
char cTemp;
strReverse=strobj;
strReverse.MakeReverse();
for(int iTemp=0;iTemp { cTemp=strReverse.GetAt(iTemp); iNum=atoi(&cTemp); if(iTemp % 2 !=0) { iNum=iNum*2; if(iNum>9) iNum-=9; } cTemp=iNum+'0'; strFinal+=cTemp; } for(iTemp=0;iTemp { cTemp=strFinal.GetAt(iTemp); iSum+=atoi(&cTemp); } if(iSum % 10 == 0) return S_OK; else return S_FALSE; } STDMETHODIMP CValidateCard::LengthCheck(BSTR bstrCCNo, BSTR bstrCCType) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here CString strType(bstrCCType),strLength(bstrCCNo); int ilen=strLength.GetLength(); if(strType=="V") { if(ilen==16)return S_OK; } else if(strType=="M") { if(ilen==16)return S_OK; } else if(strType=="A") { if(ilen==15)return S_OK; } return S_FALSE; } STDMETHODIMP CValidateCard::PrefixCheck(BSTR bstrCCNo, BSTR bstrCCType) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here CString strNumber(bstrCCNo),strType(bstrCCType); if(strType=="V") { if(strNumber.Find("4",0)>=0) return S_OK; } else if(strType=="M") { if(strNumber.Find("51",0)>=0 || strNumber.Find("52",0)>=0 || strNumber.Find("53",0)>=0 || strNumber.Find("54",0)>=0) return S_OK; } else if(strType=="A") { if(strNumber.Find("34",0)>=0 || strNumber.Find("37",0)>=0) return S_OK; } return S_FALSE; }
5. 編繹 編繹會讀取ValidateCard.rgs進行元件的自動註冊,若在 9X環境下,請執行regsvr32進行註冊,具體參見 Develo Components using VC-ATL(2-3) COM的註冊角色 同時編繹完成後,會 在De目錄下生成ValidateCreditCardServer.dll 在Debug上一層目錄下,即工程名工作空間目錄下生成ValidateCreditCardServer.tlb 這兩個檔案都可以匯入到客戶端,測試時分別會介紹這兩種方法。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-963663/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Developing COM Components using VC-ATL(1) (轉)dev
- Developing COM Components using VC-ATL(2-3) (轉)dev
- Developing COM Components using VC-ATL(2-2) (轉)dev
- Developing COM Components using VC-ATL(3-3) (轉)dev
- Developing COM Components using VC-ATL(3-4) (轉)dev
- Developing COM Components using VC-ATL(3-6) (轉)dev
- Developing COM Components using VC-ATL(3-7) (轉)dev
- Developing for ARKit 1.5 update using Unity ARKit PlugindevUnityPlugin
- [轉帖]10 Hardware Components of Oracle ExadataOracle
- Angular 2 Components CommunicateAngular
- 探索Web ComponentsWeb
- [譯] Architecture Components 之 Adding Components to your ProjectProject
- 從HTML Components的衰落看Web Components的危機HTMLWeb
- Web Components 小欖Web
- 「 重磅 」React Server ComponentsReactServer
- Styled-Components初探
- Web Components 原生元件 TrendsWeb元件
- 【譯】Web Components簡介Web
- Web Components系列(一) —— 概述Web
- Building Custom ComponentsUI
- astro中建立web componentsASTWeb
- SAP Commerce Cloud Build Manifest ComponentsCloudUI
- Flutter Flame 教程3 -- Components元件Flutter元件
- 初識 Web Components 與 StencilWeb
- 【譯】容器元件 (Container Components)元件AI
- Atag – Web Components 最佳實踐Web
- visual components premium特色功能REM
- Web Components之Custom ElementsWeb
- Altium designer 從原理圖更新至PCB時出現提示:failed to match * of * components using unique identifiersAIIDE
- XML 程式設計思想: UBL 1.0(以及 ebXML Core Components 等)(轉)XML程式設計
- Web Components 入門例項教程Web
- [譯] styled-components v3.1.0
- [譯] Web Components 的高階工具Web
- Visual Components軟體特點
- 淺析Web components的痛點Web
- Web Components 系列(五)—— 關於 TemplatesWeb
- Web Components 系列(五)—— 詳解 SlotsWeb
- CSS in JS 之 Styled-components 用法CSSJS