Component Tools Guide略读笔记(2):General Principles of Component Design

本文详细介绍了组件设计的基本概念,包括部件的分类、接口设计、CLSID的使用、初始化和终止事件的处理等内容。此外还探讨了类模块与标准模块的区别、属性和方法的实现方式以及如何提供组件的命名常量。

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Component Tools Guide/General Principles of Component Design

1. 部件基础

(1) An application or component that uses objects provided by another component is called a client. Components are characterized by their location relative to clients.

An out-of-process component is an .exe file that runs in its own process, with its own thread of execution.

An in-process component, such as a .dll or .ocx file, runs in the same process as the client.

(2) The names you select for your class modules and for their properties, methods, and events make up the interface(s) by which your component will be accessed.

(3) 确定工程的种类(有一个比较详细的讨论,不过我觉得没有略读笔记(1)里摘的那个说的清楚)。

(4) 设置工程的属性。开始一个新的component工程后,有些属性要设定:name, description, startup object(指定初始化代码的位置)。还可以设置version number, 编译, 帮助文件, version compatibility 等。

2. interface的概念及CLSID

(1) Information about the classes provided by your component is contained in a type library. In Visual Basic, the type library is included as a resource in the compiled component. Clients access the type library by setting references to it.

(2) The combination of project name and class name is sometimes referred to as a fully qualified class name, or as a programmatic ID.

Public gwdgDriveLink As SmallMechanicals.Widget

(3) Every class provided by your component has at least one interface, called the default interface, which is composed of all the properties and methods you declare in the class module.

The default interface is usually referred to by the same name as the class, though its actual name is the class name preceded by an underscore. The underscore prefix is a convention, signifying that the name is hidden in the type library.

If the class raises events, it also has an IConnectionPointContainer interface that enumerates those events. Events are outgoing interfaces, as opposed to the incoming interfaces composed of properties and methods. In other words, clients make requests by calling into your class’s properties and methods, while the events raised by your class call out to event handlers in clients.

所以,缺省的是incoming interface,而events则是out-going interfaces.

(4) GUID (pronounced goo-id) stands for Globally Unique IDentifier, a 128-bit (16-byte) number generated by an algorithm designed to ensure its uniqueness.

GUIDs are used to uniquely identify entries in the Windows registry. For example, Visual Basic automatically generates a GUID that identifies your type library in the Windows registry.

Visual Basic also automatically generates a GUID for each public class and interface in your component. These are usually referred to as class IDs (CLSID) and interface IDs (IID). Class IDs and interface IDs are the keys to version compatibility for components authored using Visual Basic.

Note   You may also see GUIDs referred to as UUIDs, or Universally Unique IDentifiers.

IID可以帮助维持版本的可兼容性。在你对你的版本做可能不兼容的改动的时候,系统会警告你,并且会建议你适当改名字。

3. Starting and Ending a Component

(1) 对于ActiveX dll和ActiveX exe而言,是不允许用forms作为启动对象的。因为这些可能导致对象初始化过长而time-out.

(2) 处理lengthy initialization有几种方法:Class_Initialize event或者在后台做using a call-back timer。但不管哪种办法都要注意用全局标志位来防止反复初始化。

(3) in-process和out-of-process组件的shut down过程有所不同。

4. Adding Classes to Components

(1) a programmatic ID or ProgID:组件名+类名,如Finance.BusinessRule

(2) 部件与其他应用的区别在于,部件至少提供1个公共类,该公共类可供client程序来使用控制。

(3) Public or Instancing Property: UserControl classes have a Public property that determines whether the class is public or private. 其他种类的部件也有相关的设置来决定类是否可供外部调用。

5. Instancing for Classes Provided by ActiveX Components

(1) 有Private, PublicNotCreatable, MultiUse, GlobalMultiUse, SingleUse, GlobalSingleUse

(2) Dependent Objects (PublicNotCreatable)

(3) MultiUse and Multithreading

(4) Global Objects有点类似application那种对象。就是不用声明对象就可以直接用方法属性啥的。好玩的特性,可是貌似我没办法用得上,因为activex control并不支持后几种实例化方法。

 

6. Coding Robust Initialize and Terminate Events

(1) Errors that occur in the Class_Initialize event procedure are returned to the point in the client at which the object was requested.

(2) Errors in the Terminate event require careful handling. Because the Terminate event is not called by the client application, there is no procedure above it on the call stack. This means that an unhandled error in a Terminate event will cause a fatal error in the component

You should always handle errors in the Class_Terminate event procedure. Errors in Class_Terminate cannot be handled by applications that use your component, and will therefore be fatal to the application.

注意:Terminater事件是在对象的引用计数为0时由vb运行环境在销毁对象前自动执行的,当时不在任何一个用户子程序环境中,不知道堆栈的情况,不知道当前的enabled error handler是哪一个。所以,即使有对象外部有on error goto 或 on error resume 也不能捕获这样的错误,从而对应用是致命的。所以,只能在terminate事件内部处理。所以,Terminal事件外的其它时间不存在这样的无法捕捉的情况。见这个帖子的讨论,感谢wangmu7206

7. Standard Modules vs. Class Modules

(1) Class module data, on the other hand, exists separately for each instance of the class. 最好避免在类模块里依赖标准模块里的公共变量,因为可能会导致逻辑上的错误。

(2) 类的静态数据

However, there may be occasions when you want a data member to be shared among all objects created from a class module. This deliberate violation of encapsulation is sometimes referred to as static class data.

You can implement static class data in a Visual Basic class module by using Property procedures to set and return the value of a Public data member in a standard module, as in the following code fragment:

' Read-only property returning application name.
Property Get ComponentName() As String
   ' The variable gstrComponentName is stored in a 
   '   standard module, and declared Public.
   ComponentName = gstrComponentName
End Property

8. Adding Properties and Methods to Classes

(1) Implementing Properties in Components:尽量用properties而不要用公共变量,主要出于稳定的考虑。

另一方面,Internally, Visual Basic generates a pair of property procedures for every public variable you declare. For this reason, declaring public variables doesn’t provide any size or performance benefits.

(2) Persisting a Component's Data:保存类的属性的初始值的方法。

While ActiveX controls have always been able to persist their data; persistence for ActiveX components is slightly different. A control stores property settings inside it's .cls file, but a component can't do that. Instead, it uses a PropertyBag object that can be saved just about anywhere – in a file, a database, a cell in a spreadsheet, or even in the registry.

(3) Data Types Allowed in Properties and Methods:见后续笔记。

9. Providing Named Constants for Your Component

(1) Although an enumeration must appear in a module that defines a class, it always has global scope in the type library. It is not limited to, or associated in any other way with the class in which you declared it.

(2) General Purpose Enumerations

(3) When you declare a variable using the name of an Enum as the data type, you’re effectively declaring the variable As Long.

(4) Occasionally you may need to provide a string constant, or a constant that isn’t an integer value. Visual Basic doesn’t provide a mechanism for adding such values to your type library as public constants, but you can get a similar effect using a global object with read-only properties.

打开链接下载源码: https://pan.quark.cn/s/c43e5bd27521 标题中的“AMD and Nvidia GOP update 1.9.6.rar”表示这是一个包含了AMD与Nvidia显卡的GOP(Graphics Output Protocol)驱动程序升级至1.9.6版本的压缩文件。该更新主要针对显卡在UEFI(统一可扩展固件接口)环境下的图形输出性能进行优化,并致力于提升系统的稳定性。在描述中提及“显卡附加UEFI引导工具,最新版”,表明此次更新内含了一个专为UEFI BIOS环境设计的显卡引导工具,或许表现为一个自启动脚本或程序,例如GOPupd.bat。通过这一工具,用户能够在UEFI模式下对显卡进行精确的配置和初始化,从而保障操作系统能够最大化地发挥显卡的效能。必需的组件包括“colorama-0.4.3”,这是一个在Windows平台上用于管理颜色控制序列的Python模块,可能在更新过程中用于生成彩色命令行显示,以增强用户交互的直观性。此外,“Visual C++Redistributable”是微软提供的运行时支持库,旨在确保基于C++编译的应用程序能够正常运行,此处可能用于更新工具或相关依赖模块。标签“uefi bios”突显了该更新与UEFI BIOS系统的紧密关联,暗示其将作用于计算机的启动序列及硬件初始化过程。压缩包内的文件清单如下: 1. GOPupd.bat - 很有可能是负责执行GPU UEFI引导更新的核心脚本。 2. #Nvidia_ROM_Info.bat 和 #AMD_ROM_Info.bat - 这两个文档可能用于采集Nvidia与AMD显卡的ROM数据,以辅助识别显卡型号并执行适配性验证。 3....
代码下载地址: https://pan.quark.cn/s/a2e2c95e6128 意法半导体(STMicroelectronics)研发的STM32H750是一款性能优越的微控制器,属于STM32H7系列,拥有卓越的处理性能以及多元化的外设接口。在此项工作中,我们将研究如何借助STM32H750达成串口空闲中断(IDLE interrupt)的运用、借助DMA完成UART(通用异步收发传输器)的数据传输,并且探究如何运用STM32CubeMX配置并构建MDK5(Keil uVision5)项目。串口空闲中断是串口通信中的一个核心功能,当串口在一段时间内没有进行数据交换时,会引发该中断。这种功能在需要实时监测串口状态的应用场合中非常有价值,比如,在等待特定指令或需要降低能耗的情况下。在STM32H750中,设定串口空闲中断通常包含以下几个环节: 1. 串口设置:在STM32CubeMX中选定相应的UART接口,并激活中断功能。 2. 中断优先级设定:按照应用需求设定中断优先级。 3. 中断服务函数注册:在程序代码中定义中断服务函数以应对中断事件。 4. 启用串口空闲中断:在初始化代码中激活串口的IDLE位,使能中断。 DMA(Direct Memory Access)传输是一种高效的数据传输机制,它允许外设直接与内存进行交互,无需CPU的介入,从而减轻了CPU的工作负担。在STM32H750中,我们可以运用DMA配合UART来接收数据: 1. DMA配置:在STM32CubeMX中为UART选择合适的DMA通道,并设定传输特性。 2. UART配置:将UART设置为DMA模式,并指定接收缓冲区的地址。 3. 中断配置:开启DMA传输完成中断,以便在数据接收完...
源码直接下载地址: https://pan.quark.cn/s/d64de7ee3e36 STM32CubeIDE是由STMicroelectronics(意法半导体)开发的一款集成开发环境,其核心功能是针对STM32系列微控制器进行优化,并集成了包括源代码编写、编译执行、调试检测以及项目参数设置在内的完整开发工具集。该开发平台依托于Eclipse系统框架构建,旨在为编程人员营造一个便捷且生产力高的工作场景。1.9.0版本属于其产品线中的一个成熟版本,通常包含了若干性能增强措施以及新特性的集成。在嵌入式系统的构建过程中,代码的自动完成机制是一项关键的辅助技术,它能够显著提升工作速率并降低操作失误。专门为这一目的设计的STM32CubeIDE 1.9.0自动代码补全组件,能够有效满足开发者的相关需求。通过将压缩文件中的内容部署到STM32CubeIDE安装路径下的`plugins`子目录中,该插件即可被系统自动检测并激活,从而在代码编写阶段,系统能够基于上下文信息智能地预判并展示潜在的函数名称、变量定义或常量值,进而辅助开发者迅速完成输入任务。基于ARM Cortex-M架构的STM32系列微控制器,在物联网装置、工业自动化系统、个人消费类电子设备等领域具有广泛的部署。在这些应用场景中,单片机扮演着核心角色,而STM32凭借卓越的处理性能、多样化的外部接口配置以及出色的能源控制能力,已成为众多开发者的首选方案。STM32CubeIDE所提供的自动代码补全功能,对于初入行业的开发者而言尤为适宜,因为它能够实时呈现API函数的相关信息,涵盖函数标识符、参数的数据类型与数目,乃至函数的返回类型,从而协助开发者精准地运用STM32的固件库。不仅如此,即便对于已经熟练掌握ST...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值