VB 你清楚了吗?

 

Because, I don't know it's lucky or not, I have to contact some legency VB6 code, totally over 300 Dlls. When I am doing sth. on the project, modification, recompile, fix a little bug etc. I find there are a lots basic concepts that are NOT clear, not only me, but our programmers. When I ask them, they can't give me a clear explaination about some. I did some "google" job, and post some articles here, for myself to review, and for somebody else who needs to clear something! Here is the first one.

 


 
Visual Basic Binary Compatibility
What is binary compatibility and why is it important?
In order to answer these questions, you first need to understand a little about how Visual Basic maps to the Microsoft Component Object Model (COM). It's important to understand how VB utilises COM technologies if you are to maximise the capabilities of VB to deliver component-based solutions and also if you are to avoid the infamous "Error 429 - ActiveX component can't create object".
VB, ActiveX Components And COM
Visual Basic ActiveX (DLL, EXE, control and document) projects create COM components. All COM components contain one or more component classes and COM requires each component class to implement one or more interfaces. COM interfaces provide a standard mechanism by which a client can invoke the services of a server component.
COM makes heavy use of the Windows registry and requires all COM components to register information about themselves within the registry before clients can access their services. To ensure different components do not clash, COM uses globally unique identifiers (known as GUIDs) which are computed using a special algorithm.
VB public classes correspond to COM component classes and VB automatically creates a default interface for each class. Each component class has a unique GUID (known as a CLSID) as does each interface implemented by a class (known as an IID). Again, VB automatically creates the unique identifiers on behalf of the programmer at compilation time based on thecompatibility setting selected for the project.
A COM component class can also be accessed via its programmatic identifier (referred to as its ProgID). This is a name constructed from the type library name (VB project 'Name' attribute) and VB class 'Name' attribute separated by a period e.g. 'MyApp.MyClass'. (The VB 'CreateObject' command takes a ProgID as one of its parameters to create an instance of an object.)
Type Libraries
Information about a COM component's classes, their interfaces, methods, properties, enums etc. are typically stored in a type library and referenced by VB projects. This information is used by the VB IDE to display intelli-sense information and component details within the Object Browser window.
Type library information can be defined using Interface Definition Language (IDL) and compiled into a type library using the MIDL compiler. Fortunately, VB programmers are spared this exercise as VB does this work behind the scenes and automatically binds the type library into the compiled component binary. VB also registers the component, including a reference to the type library GUID (referred to as the LIBID).
Note: If you wish to view the IDL for your VB components, you can do so using the OleView utility which ships with Visual Studio Enterprise Edition. Run the utility and select the 'View TypeLib...' option from the 'File' menu. This can be particularly useful when trouble-shooting unexpected binary compatibility issues.
Windows Registry
When an ActiveX component is registered on a machine, a number of registry entries are created. For example, consider an ActiveX DLL component containing a public class called 'AXTest' with a public method name 'TestMethod1' and the VB project name 'VBAXTest'. When the compiled component (VBAXTest.DLL) is deployed to 'C:/Program Files/Test' and registered, a number of entries are written under HKEY_CLASSES_ROOT as follows (not all entries are shown):

CLSID
 
{E2366527-7621-4CB3-BC1B-7527C167BD23}
 
 
InprocServer32
 
 
 
(Default)
REG_SZ
C:/Program Files/Test/VBAXTest.dll
 
 
 
ThreadingModel
REG_SZ
Apartment
 
 
ProgID
 
 
 
(Default)
REG_SZ
VBAXTest.AXTest
 
 
TypeLib
 
 
 
(Default)
REG_SZ
{62166784-093E-498F-BDE0-C8DAF8CB40A6}
Interface
 
{B36EE049-7504-4047-BA93-684A2380A820}
 
 
ProxyStubClsid
 
 
 
(Default)
REG_SZ
{00020420-0000-0000-C000-000000000046}
 
 
ProxyStubClsid32
 
 
 
(Default)
REG_SZ
{00020420-0000-0000-C000-000000000046}
 
 
TypeLib
 
 
 
(Default)
REG_SZ
{62166784-093E-498F-BDE0-C8DAF8CB40A6}
 
 
 
Version
REG_SZ
1.0
TypeLib
 
{62166784-093E-498F-BDE0-C8DAF8CB40A6}
 
 
1.0
 
 
 
(Default)
REG_SZ
VB ActiveX Test Component
 
 
 
0
 
 
 
 
win32
 
 
 
 
 
(Default)
REG_SZ
C:/Program Files/Test/VBAXTest.dll
VBAXTest.AXTest
 
CLSID
 
 
(Default)
REG_SZ
{E2366527-7621-4CB3-BC1B-7527C167BD23}

Visual Basic References
When you display the Project References dialog within the VB IDE, VB scans the 'HKCR/TypeLib' section of the registry and lists the friendly name from the version key (i.e. in our example 'VB ActiveX Test Component'). If a reference is selected then VB uses the value under the 'win32' key to locate the type library in the file system, which it then loads so that it can populate the object browser and the intelli-sense lists in the IDE. The LIBID of the selected type library is added to the project source file as a 'Reference=' line.
 BEWARE  VB defaults to referencing the latest version of a type library. If you compile an application against a later type library version and release the updated application to existing users whilst failing to release the updated component, users will encounter error 429 with the updated application!
ActiveX Component Clients
If we consider our example further by creating a standard Exe project that references our test ActiveX server and contains the following code in the Form_Load event of the application’s main form.
Private Sub Form_Load
    Dim objTest As AXTest
    Set objTest = New AXTest
    objTest.TestMethod1
End Sub
When the client project is compiled, the component Class ID (CLSID) and Interface ID (IID) of AXTest is compiled into the executable (the CLSID is used by COM to lookup in the registry the physical location in the file system of the file containing the class). This means that if either ID changes in the ActiveX component then the dreaded Error 429 ActiveX Cannot Create Component will be displayed and without error handling, the executable will simply terminate.
When an ActiveX component is compiled, there are three possible project compatibility settings:
With this setting, new class ID’s, new interface ID’s and a new type library ID will be generated by VB each time the ActiveX component project is compiled. This will cause any compiled client components to fail (with error 429!) and report a missing reference to the 'VB ActiveX Test Component' when a client project is loaded in the VB IDE.
 Tip  Use this setting to compile the initial release of a component to other developers.
With this setting, VB will generate new interface ID’s for classes whose interfaces have changed, but will not change the class ID’s or the type library ID. This will still cause any compiled client components to fail (with error 429!) but will not report a missing reference to the 'VB ActiveX Test Component' when a client project is loaded in the VB IDE. Recompilation of client components will restore them to working order again.
 Tip  Use this setting during the initial development and testing of a component within the IDE and before the component is released to other developers.
VB makes it possible to extend an existing class or interface by adding new methods and properties etc. and yet still retain binary compatibility. It can do this, because it silently creates a new interface ID for the extended interface and adds registration code to register the original interface ID but with a new Forward key containing the value of this new interface ID. COM will then substitute calls having the old ID with the new ID and hence applications built against the old interface will continue to work (assuming the inner workings of the component remain backward compatible!).
With this setting, VB will not change any of the existing class, interface or type library ID’s, however in order that it can do so, VB requires the project to specify an existing compiled version that it can compare against to ensure that existing interfaces have not been broken.
 Tip  Use this setting following the release of a component to other developers.
Breaking Compatibility
When the need to break compatibility arises, be sure to tackle it head on and make a clean break. To do so, create a new version of the project with compatibility set to 'No Compatibility'. Next, change the project 'Name' attribute and compile to a different component name. Taking this approach ensures that existing applications can continue to work with the old component while new versions can use the new component.
Working With Binary Compatibility And Avoiding Error 429
The first time an ActiveX component is built for release then the 'No Compatibility' setting should be selected thereby causing new class, interface and type library ID’s to be generated. (Only use 'Project Compatibility' during the initial development of a component within the IDE and before releasing the component to other developers.)
A copy of the released component should then be placed into a sub-folder (preferably named 'Compat') beneath the project folder and the compatibility setting changed to 'Binary Compatible' with the compatible image being set to the component in the 'Compat' sub-folder.
The following rules ensure binary compatibility is maintained:
·  The name of the project cannot change.
·  The names of any public classes cannot change.
·  The names of any public methods or properties cannot change.
·  The number of parameters to any public method cannot change.
·  The data types of the parameters cannot change.
·  The calling convention (ByRef, ByVal) of the parameters cannot change.
·  The names of public enums cannot change.
·  The order/values of elements in public enums cannot change.
·  The names of public user-defined types cannot change.
·  The names and data types of elements in public user-defined types cannot change.
·  If a public class implements user-defined interfaces then the 'Implements' statement cannot change.
Whenever the component is amended, always update the component's version information to allow different versions to be correctly distinguished. You should also update the compatible image in the 'Compat' folder with the latest compiled component binary once the component has been successfully tested and released to other developers. It is a good habit to do this even when interfaces remain unchanged
标题基于Python的汽车之家网站舆情分析系统研究AI更换标题第1章引言阐述汽车之家网站舆情分析的研究背景、意义、国内外研究现状、论文方法及创新点。1.1研究背景与意义说明汽车之家网站舆情分析对汽车行业及消费者的重要性。1.2国内外研究现状概述国内外在汽车舆情分析领域的研究进展与成果。1.3论文方法及创新点介绍本文采用的研究方法及相较于前人的创新之处。第2章相关理论总结和评述舆情分析、Python编程及网络爬虫相关理论。2.1舆情分析理论阐述舆情分析的基本概念、流程及关键技术。2.2Python编程基础介绍Python语言特点及其在数据分析中的应用。2.3网络爬虫技术说明网络爬虫的原理及在舆情数据收集中的应用。第3章系统设计详细描述基于Python的汽车之家网站舆情分析系统的设计方案。3.1系统架构设计给出系统的整体架构,包括数据收集、处理、分析及展示模块。3.2数据收集模块设计介绍如何利用网络爬虫技术收集汽车之家网站的舆情数据。3.3数据处理与分析模块设计阐述数据处理流程及舆情分析算法的选择与实现。第4章系统实现与测试介绍系统的实现过程及测试方法,确保系统稳定可靠。4.1系统实现环境列出系统实现所需的软件、硬件环境及开发工具。4.2系统实现过程详细描述系统各模块的实现步骤及代码实现细节。4.3系统测试方法介绍系统测试的方法、测试用例及测试结果分析。第5章研究结果与分析呈现系统运行结果,分析舆情数据,提出见解。5.1舆情数据可视化展示通过图表等形式展示舆情数据的分布、趋势等特征。5.2舆情分析结果解读对舆情分析结果进行解读,提出对汽车行业的见解。5.3对比方法分析将本系统与其他舆情分析系统进行对比,分析优劣。第6章结论与展望总结研究成果,提出未来研究方向。6.1研究结论概括本文的主要研究成果及对汽车之家网站舆情分析的贡献。6.2展望指出系统存在的不足及未来改进方向,展望舆情
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值