A preliminary study of COM technology (2)

Source: Internet
Author: User
Tags uuid win32

Three, purely manually create a COM component

1, from the construction project to the implementation of registration

In this process we will complete three steps: Create DLL entry function, define interface file, implement registration function

1.1 Create a type Win32 DLL project

Create a Win32 DLL project called Mathcom.

In the second step of the wizard, select the "A smiple DLL project" option. Of course, if you choose an empty project, then you complete the DllMain definition yourself.

1.2 Defining interface Files

Generates an interface file named Mathcom.idl. and add this file to the project that you just created.

Mathcom.idl file
MathCOM.idl:IDL Source for MathCOM.dll
//
This file is processed by the MIDL tool to
produce the type library (mathcom.tlb) and marshalling code.
Import "Oaidl.idl";
Import "Ocidl.idl";
[
UUID (faeae6b7-67be-42a4-a318-3256781e945a),
helpstring ("Isimplemath Interface"),
Object
Pointer_default (Unique)
]
Interface Isimplemath:iunknown
{
HRESULT ADD ([in]int nop1,[in]int nop2,[out,retval]int * pret);
HRESULT Subtract ([in]int nop1,[in]int nop2,[out,retval]int * pret);
HRESULT Multiply ([in]int nop1,[in]int nop2,[out,retval] int * pret);
HRESULT Divide ([in]int nop1,[in]int nop2,[out,retval]int * pret);
};
[
UUID (01147C39-9DA0-4F7F-B525-D129745AAD1E),
helpstring ("Iadvancedmath Interface"),
Object
Pointer_default (Unique)
]
Interface Iadvancedmath:iunknown
{
HRESULT factorial ([in]int nop1,[out,retval]int * pret);
HRESULT Fabonacci ([in]int nop1,[out,retval]int * pret);
};
[
UUID (ca3b37ea-e44a-49b8-9729-6e9222cae844),
Version (1.0),
helpstring ("mathcom 1.0 Type Library")
]
Library Mathcomlib
{
Importlib ("Stdole32.tlb");
Importlib ("Stdole2.tlb");
[
UUID (3bcfe27e-c88d-453c-8c94-f5f7b97e7841),
helpstring ("mathcom Class")
]
CoClass mathcom
{
[Default] interface Isimplemath;
Interface Iadvancedmath;
};
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.