Developing COM Components Using VC-ATL (3-5)

xiaoxiao2021-03-06  38

4. Write the code ValidateCard.cpp list for implementing function functions

// 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 ("Master") == 0)

BSTRCCTYPE = SYSALLOCSTRING (Olestr ("m");

Else IF ("American") == 0)

BSTRCCTYPE = SYSALLOCSTRING (Olestr ("a");

Else

{

* VAL = 0;

Return S_FALSE;

}

IF ((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;

}

ITEMP = 0; itemp

{

Ctemp = strfinal.get (item); 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);

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. Cenine

Clearness will read the ValidateCard.RGS file automatically registration, if you run the Regsvr32 program, please see

Developing COMPONENTS Using VC-ATL (2-3) COM object registration role

At the same time, after completion, will

Generate validatecreditcardServer.dll in debug directory

In the Debug on the first floor directory, the engineering name workspace directory generates validatecreditcardServer.tlb

Both files can be imported into the client, and the two methods are introduced separately.

Author Blog:

http://blog.9cbs.net/callzjy/

转载请注明原文地址:https://www.9cbs.com/read-77819.html

New Post(0)