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