Create an IDL file after the component
ValidatecreditCardServer.IDL list
Import "OAIDL.IDL";
Import "OCIDL.IDL";
[
Object,
UUID (B1D1C73C-E340-4FDC-8734-92ecec64DC4E),
Dual,
Helpstring ("iValidateCard Interface",
Pointer_DEFAULT (UNIQUE)
]
Interface ivalidatecard: idispatch
{
}
[
UUID (B3404054-C33E-4931-B737-5783CEEFECDB),
Version (1.0),
Helpstring ("ValidatecreditcardServer 1.0 Type Library")
]
Library ValidatecreditcardServerLib
{
Importlib ("stdole32.tlb");
Importlib ("stdole2.tlb");
[
UUID (C79635D2-7B86-4B20-A83C-0565DCA54C3C),
Helpstring ("ValidateCard Class")
]
CoClass ValidateCard
{
[Default] interface ivalidatecard;
}
}
The black body portion in the article represents the code formed after the assembly class is added in the frame, and only the type library portion is added to the framework, and after creating the component class, we can see the user interface of a component class, below It is a component class that nested in the type library. Oh, the three parts are all.
In addition, it also explains the use of ValidatecreditcardServerlib these letters. Everyone thinks there is no? Oh, it is used when using the name space in the client. See Visual C components in detail.
3. Add the functionality of the component.
To achieve this, you have to increase the function of the validity of the credit card. How to add functions to your components, follow these steps:
In the ClassView card of the Workspace in the left side of the VC work platform, find the interface iValidateCard item, press the right click, select Add method ..., add the add method to interface dialog box, enter the function of the function you want to add in the dialog box. Name, parameters, and return value types. Here, we entered in Method Name
Validatecreditcard
Enter in Parameters
[in] bstr bstrccno, [in] BSTR BSTRCCTYPE, [OUT, RETVAL] long * VAL
Then, press the confirmation button to exit.
Similarly to the following three functions
Function function
Method Name
Parameters
Check if the number of the credit card is legal
Luhncheck
[in] BSTR BSTRCCNO, [IN] BSTR BSTRCCTYPE Test Credit Card Length Level
Lengthcheck
[in] BSTR BSTRCCNO, [IN] BSTR BSTRCCTYPE Test credit card type is legal
PrefixCheck
[in] bstr bstrccno, [in] BSTR BSTRCCTYPE
Now you can see the change of the interface definition language file created for your component, you will see the entry of all functions added above in the IDL file validatecreditcardserver.idl.
ValidatecreditCardServer.idl List // ValidatecreditcardServer.idl: IDL Source for ValidatecreditCardServer.dll
//
// this file will be processed by the Mid Tool To
// produted the Type Library (ValidatecreditcardServer.tlb) and Marshalling Code.
Import "OAIDL.IDL";
Import "OCIDL.IDL";
[
Object,
UUID (B1D1C73C-E340-4FDC-8734-92ecec64DC4E),
Dual,
Helpstring ("iValidateCard Interface",
Pointer_DEFAULT (UNIQUE)
]
Interface ivalidatecard: idispatch
{
[ID (1), Helpstring ("Method Validatecreditcard")] HRESULT VALIDATECREDITCARD ([in] BSTR BSTRCCNO, [IN] BSTR BSTRCCTYPE, [OUT, RETVAL] long * VAL);
[ID (2), Helpstring ("Method Luhncheck")] HRESULT Luhncheck ([in] BSTR BSTRCCNO, [IN] BSTR BSTRCCTYPE);
[ID (3), Helpstring ("Method Lengthcheck")] HRESULT Lengthcheck ([in] BSTR BSTRCCNO, [IN] BSTR BSTRCCTYPE);
[ID (4), Helpstring ("Method PrefixCheck")] HRESULT Prefixcheck ([in] BSTR BSTRCCNO, [IN] BSTR BSTRCCTYPE);
}
...
In addition, it also adds the entry of the function in the implementation of the component class's implementation class.
ValidateCard.h list
// ValidateCard.h: Declaration of the cvalidatecard
#ifndef __validatecard_h_
#define __validatecard_h_
#include "resource.h" // main symbols
/
// CVALIDATECARD
Class ATL_NO_VTABLE CVALIDATECARD:
Public CComobjectrootex
Public ccomcoclass
Public IDispatchImpl
{
PUBLIC:
CVALIDATECARD ()
{
}
Declare_registry_resourceId (idR_validatecard)
Declare_protect_final_construct ()
Begin_com_map (CVALIDATECARD)
COM_ITERFACE_ENTRY (IVALIDATECARD)
COM_ITERFACE_ENTRY (Idispatch)
END_COM_MAP ()
// ivalidatecardpublic:
STDMETHOD (/ * [in] * / bstr bstrccno, / * [in] * / bstr bstrcctype);
STDMETHOD (/ * [in] * / bstr bstrccno, / * [in] * / bstr bstrcctype);
STDMETHOD (/ * [in] * / bstr bstrccno, / * [in] * / bstr bstrcctype;
STDMETHOD (VALIDATECREDITCARD) (/ * [in] * / bstr bstrcccno, / * [in] * / bstr bstrcctype, / * [out, retval] * / long * val);
}
#ENDIF / / __ VALIDATECARD_H_
(Space limit, endless, to be continued)
Author Blog:
http://blog.9cbs.net/callzjy/