Developing COM Components using VC-ATL(3-7)

类别:VC语言 点击:0 评论:0 推荐:

 

最后让我们分析一下C:\VCTestVCComProj\Debug\ValidateCreditCardServer.tlh作为Developing COM Components using VC-ATL(3)的结尾吧。

 

ValidateCreditCardServer.tlh清单

 

// Created by Microsoft (R) C/C++ Compiler Version 12.00.8168.0 (ad98f509).

//

// c:\vctestvccomproj\debug\ValidateCreditCardServer.tlh

//

// C++ source equivalent of Win32 type library ..\ValidateCreditCardServer\Debug\ValidateCreditCardServer.dll

// compiler-generated file created 12/19/03 at 03:29:03 - DO NOT EDIT!

 

#pragma once

#pragma pack(push, 8)

 

#include <comdef.h>

 

namespace VALIDATECREDITCARDSERVERLib {…………………………………..………名字空间

 

//

// Forward references and typedefs

//

 

struct /* coclass */ ValidateCard;………………………………………………………………..….. 组件类

struct __declspec(uuid("b1d1c73c-e340-4fdc-8734-92ecec64dc4e"))

/* dual interface */ IValidateCard;………………………………………………….………………用户接口

 

//

// Smart pointer typedef declarations

//

 

_COM_SMARTPTR_TYPEDEF(IValidateCard, __uuidof(IValidateCard));………..………智能指针

 

//

// Type library items

//

 

struct __declspec(uuid("c79635d2-7b86-4b20-a83c-0565dca54c3c"))…………………组件类CLSID

ValidateCard;

    // [ default ] interface IValidateCard

 

struct __declspec(uuid("b1d1c73c-e340-4fdc-8734-92ecec64dc4e"))……………………用户接口IID

IValidateCard : IDispatch

{

    //

    // Wrapper methods for error-handling

    //

 

    long ValidateCreditCard (

        _bstr_t bstrCCNo,

        _bstr_t bstrCCType );

    HRESULT LuhnCheck (

        _bstr_t bstrCCNo,

        _bstr_t bstrCCType );

    HRESULT LengthCheck (

        _bstr_t bstrCCNo,

        _bstr_t bstrCCType );

    HRESULT PrefixCheck (

        _bstr_t bstrCCNo,

        _bstr_t bstrCCType );……………………………………………….………….. 接口方法(对外)

 

    //

    // Raw methods provided by interface

    //

 

    virtual HRESULT __stdcall raw_ValidateCreditCard (

        BSTR bstrCCNo,

        BSTR bstrCCType,

        long * val ) = 0;

    virtual HRESULT __stdcall raw_LuhnCheck (

        BSTR bstrCCNo,

        BSTR bstrCCType ) = 0;

    virtual HRESULT __stdcall raw_LengthCheck (

        BSTR bstrCCNo,

        BSTR bstrCCType ) = 0;

    virtual HRESULT __stdcall raw_PrefixCheck (

        BSTR bstrCCNo,

        BSTR bstrCCType ) = 0;…………………………………………………..……. 接口方法(对内)

};

 

//

// Wrapper method implementations

//

 

#include "c:\vctestvccomproj\debug\ValidateCreditCardServer.tli"………….. 类型库实现文件

 

} // namespace VALIDATECREDITCARDSERVERLib……………………………..……….. 名字空间

 

#pragma pack(pop)

 

参照COM组件端C:\ValidateCreditCardServer\ValidateCreditCardServer.idl

 

ValidateCreditCardServer.idl清单

// ValidateCreditCardServer.idl : IDL source for ValidateCreditCardServer.dll

//

 

// This file will be processed by the MIDL tool to

// produce the type library (ValidateCreditCardServer.tlb) and marshalling code.

 

import "oaidl.idl";

import "ocidl.idl";

         [

                   object,

                   uuid(B1D1C73C-E340-4FDC-8734-92ECEC64DC4E),……………………………. IID部分

                   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);

         };

 

[

         uuid(B3404054-C33E-4931-B737-5783CEEFECDB),………………………………… LIBID部分

         version(1.0),

         helpstring("ValidateCreditCardServer 1.0 Type Library")

]

library VALIDATECREDITCARDSERVERLib

{

         importlib("stdole32.tlb");

         importlib("stdole2.tlb");

 

         [

                   uuid(C79635D2-7B86-4B20-A83C-0565DCA54C3C),…………………….……CLSID部分

                   helpstring("ValidateCard Class")

         ]

         coclass ValidateCard

         {

                   [default] interface IValidateCard;

         };

};

小结:

Developing COM Components using VC-ATL(3)主要介绍了Visual C++与Visual Basic编写的组件的相互间的调用。在接下来一篇里将介绍双接口。

 

Developing COM Components using VC-ATL(3)完 

本文地址:http://com.8s8s.com/it/it1309.htm