VC 创建 Component Object Model

ATL Project Wizard

2025-03-05

Written by: tdtc

ATL工程

File->New->Project

name: testATL

Note: name即是要生成的DLL文件
project type project name

选择”MFC/ATL”中”ATL Project”:

Default

project property

Add ATL Simple Object

右击项目名称

ATL Simple Object:

atl simple object - new

设置

atl simple object - progID

IE支持

atl simple object - Support

添加IDL方法

Tab switching from “Solution Explorer” to “Class View”

vs2022: View -> Class View

Select the interface, Right-click -> add -> add method

name: ItestSOW

atl interface - add 添加方法名称以及参数

atl interface - property

MIDL attribute

	[id(1), helpstring("add method")] HRESULT Add([in] LONG x, [in] LONG y, [out, retval] LONG* ret);
	[id(2), helpstring("sub method")] HRESULT Sub([in] LONG x, [in] LONG y, [out, retval] LONG* ret);

test

@echo
cd /d %~dp0
Regsvr32 xbfInfo.dll
<Visual-Studio Installation Path>\vcruntime140d.dll

and

C:\Windows\SysWOW64\ucrtbased.dll

放到project目录

VB Project

Project -> Add Reference vb import dll

按钮事件:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj As New testATLLib.testSOW
        Dim int1 As Long

        'vs2010/vs2013'int1 = obj.Add(2, 3)
        obj.Add(2, 3, int1)
        Label1.Text = int1
    End Sub

拷贝Interop.testATLLib.dll和WindowsApplication1.exe即可 运行

Ref