You can tell VB6 to reuse the GUID (IID CLSID LIBID, etc.) by changing the project compatibility setting to "No Compatibility" to "Binary Compatibility". These options can be found in the section "Project-> Your-Project Properties". The compatibility setting is located on the Component tab of the Project Properties window. There are three options:
- No compatibility
- Project compatibility
- Binary compatibility
Here MSDN talks about them:
No compatibility
There is no compatibility with this setting. Visual Basic creates new interface identifiers and class identifiers each time you create or compile your project. Each version can only be used with applications created to work with this specific component layout.Project compatibility
With this setting you can make your project compatible with a specific component project. While the new type is library information, the type library identifier so that test projects can still reference the project component. This option is to maintain compatibility during testing. Therefore, as soon as a component is freed, it behaves in the same way as the “No compatibility” parameter.
Binary compatibility
When you compile your project, Visual Basic only creates new classes and Interface Identifiers if necessary. This saves class and interface identifiers from the previous version (s) so that programs compiled using the earlier version will continue to work. if you make changes that result in an incompatible version, Visual Basic will warn you. If you want to maintain compatibility with older, released versions of the ActiveX component, this is the setting you need to use.
It looks like you are currently compiling No compatibility . As stated in the MSDN article, you need to use Binary Compatibility to keep older versions of your components compatible with older versions. You can do it now by following these steps:
Compile each project once with No Compatibility
Save these “clean” versions to a folder that assembly users can easily access, such as a network share, or put them in the source code.
Go back and change all projects to “Binary Compatibility” and point “Compatible File” to the corresponding version that you just saved on the network / in the original control (do not point the compatible file to the path to which you are compiling the project. Compatible the file must be a separate copy of the source component, which will not change. It exists only so that VB can copy the identifier from this file to your project when it is recompiled).
Each time you recompile your projects, they will reuse the GUID from compatible (original) versions of the components.
EDIT: As Joe pointed out in the comments, you also need to find out when the interfaces of your class have changed (that is, when the interface has changed so much that you can maintain compatibility with previous versions for longer). When this happens, you want to make a clean break with previous versions of the components: recompile the new “clean” version (ie No compatibility) and use this new version as a compatible file in future builds. However, it is important to note that you should start over when the interfaces of your class (properties and methods) change. In fact, VB will warn you when a project is no longer compatible with a previous version of a component.
If you want to live on the edge ...
Where I work, we tend to (ab) use No Compatibility for most of our projects, although this is not the right way to do something (you should use Binary Compatibility). Laziness was acquired in our company, because we have an automatic assembly tool that compiles all our projects for us, and one of the main features of this tool is that it can automatically restore broken links to projects between projects. Since the build tool fixes this for us, there are fewer incentives to use binary compatibility.
Why is binary compatibility better (or ... why you shouldn't do what we do)
A few reasons why binary compatibility is usually the best choice:
Microsoft says that
If all your components are compatible with previous versions of the software, you can easily recompile one component and redistribute it to your customers. This simplifies the deployment of patches / patches. If you use “No Compatibility” in your projects, you will have to recompile and redistribute your entire application each time a small patch is required, because newer components (probably) will not work with older components.
You do your part to support the COM standard: in COM, the class identifier and interface identifier must uniquely identify the class or interface. If your classes and / or interfaces have not changed between assemblies, then there is no reason to generate a new identifier for these classes and interfaces (in fact, the same class will have several identifiers). Binary Compatiblity allows you to maintain the same identifier in assemblies, which means that you are a good citizen and follow the COM conventions.
Less registry noise. If you always deploy new components for clients that are not compatible with older versions, each new version adds new information to the registry. Each new interface and class identifier must be registered, among other things. If you store all Binary Compatible, then the installer should only add registry keys in one place, since your class identifier and interface identifier will not change.
If you publish a public API or component that consumes other third-party applications, you will definitely want to use binary compatibility so as not to violate third-party software that depends on your code.