In this article I will show you how to build private assemblies to make those personal or small business COM objects register free.
Note: The examples provided in this article are for classic VB however the same rules for creating private assemblies still apply.
- 1
- Building an ActiveX DLL Test Project
This section will describe the steps to create a (ActiveX DLL) files that will be used for testing your assemblies.
The following locations and directory layouts will be used to help you follow this article.
C:\LibDogs
C:\LibDogs\PitBullClass
C:\LibDogs\Application
C:\LibDogs\Release
1) Fire up a new project an choose new ActiveX DLL
2) Name Project1: LibDogs
3) Name Class1: PitBull
4) Add the following code snippet to Pitbull.cls
1: 2: 3: 4: 5: | Option Explicit Public Sub Bark() MsgBox "Pitbull barks!" End Sub |
5) From the main IDE menu choose File / Make. Change the name to: Pitbull.dll then Save to C:\LibDogs\PitbullClass\P
6) From the main IDE menu choose Project / Properties. Choose the Component Tab and select Binary Compatability. Click OK.
7) Go back to step 5 and compile PitBull.dll overwrite the existing and save your project to C:\LibDogs\PitbullClass
8) You're DONE!
Steps (5 - 7) are important to remember when you go to release your application. We will need the correct GUID values located in the class to create the private assembly later (Binary Compatabilty) options is what you should do just before deploying your application because it makes sure the GUID values don't change.
- 2
- Building a GUID viewer or using OLE View
You can use OLE View a standard application shipped with visual studio. We will be using TypeLibInfo library instead for this article.
1) Open a new Standard Project and Add a command button to the form.
2) Click Project / References. Add (TypeLib Information) TLBINF32.DLL
3) Add the following code the form.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: |
Private Sub Command1_Click()
Dim tb As TLI.TLIApplication
Dim Info As TypeLibInfo
Set tb = New TLI.TLIApplication
Set Info = tb.TypeLibInfoFromFile("C:\LibDogs\PitBullClass\pitbull.dll")
Debug.Print "CLSID = " & Info.CoClasses.Item(1).Guid
Debug.Print "IID = " & Info.Interfaces.Item(1).Guid
Debug.Print "TLBID = " & Info.Guid
Set tb = Nothing
End Sub |
4) Run the project and click the button. These are the GUID values we need to use with the assembly we build in the next step.
- 3
- Building the private assembly
1) Locate your project working directory C:\LibDogs\PitbullClass
2) Create a new text document and rename it: Pitbull.x.manifest
3) Now open the file using notepad and add the following assembly.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="pitbull.x"
version="1.0.0.0"/>
<file name = "pitbull.dll">
<comClass
clsid="{ACB79DBD-CF23-4C35-9223-396194DCD6A3}"/>
<typelib
tlbid="{C16F2BBA-73ED-4F9A-AF6A-CE5A718C81E5}"
version="1.0"
helpdir=""/>
</file>
<comInterfaceExternalProxyStub
name="_PITBULL"
iid="{95C31AB9-F941-42AA-8FC3-CB9B79B10207}"
proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
baseInterface="{00000000-0000-0000-C000-000000000046}"
tlbid = "{C16F2BBA-73ED-4F9A-AF6A-CE5A718C81E5}"/>
</assembly> |
The tags that need to be updated with your information are outlined below.
Replace the GUID values to reflect the GUID values that displayed from the GUID viewer project.
1: 2: 3: 4: 5: 6: 7: |
name="[i]pitbull.x[/i]"
<file name = "[i]pitbull.dll[/i]">
clsid="{[i]ACB79DBD-CF23-4C35-9223-396194DCD6A3[/i]}"
tlbid="{[i]C16F2BBA-73ED-4F9A-AF6A-CE5A718C81E5[/i]}"
name="_[i]PITBULL[/i]"
iid="{[i]95C31AB9-F941-42AA-8FC3-CB9B79B10207[/i]}" |
- 4
- Creating the Application project
1) Fire up a new Standard Project.
2) Add a command button to the form.
3) Click Project / Reference. Add PitBull.dll C:\LibDogs\PitbullClass\Pi
4) Add the following code to the form.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: | Option Explicit Dim MyDog As PitBull Private Sub Command1_Click() MyDog.Bark End Sub Private Sub Form_Load() Set MyDog = New PitBull End Sub |
5) Click File / Make . Rename the file to: Pitbullapp.exe Save it to C:\LibDogs\Application
- 5
- Creating the Application manifest
1) Locate your working directory C:\LibDogs\Application
2) Create a new text document and rename it to: PitBullApp.exe.manifest
3) Add the following code.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity type = "win32" name = "PitbullApp" version = "1.0.0.0"/> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="pitbull.X" version="1.0.0.0"/> </dependentAssembly> </dependency> </assembly> |
- 6
- Testing your private assembly
1) Locate all of the following files and copy them to Release directory. C:\LibDogs\Release\
a.) C:\LibDogs\PitBullClass\
b.) C:\LibDogs\PitBullClass\
c.) C:\LibDogs\Application\P
d.) C:\LibDogs\Application\P
2) Lets un-register pitbull.dll on the system. Run the following line from a command prompt.
1: | regsvr32 /u C:\LibDogs\Release\pitbull.dll |
Go to C:\LibDogs\Release folder and execute Pitbullapp.exe Click the button. If you see a message box your assembly worked!.
If you need to add more than one DLL then build up the .x.manifest from the steps, and all you need to do is update pitbull.exe.manifest with an additional entry.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: | <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="pitbull.X" version="1.0.0.0"/> </dependentAssembly> </dependency> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="ANOTHERDLL.X" version="1.0.0.0"/> </dependentAssembly> </dependency> |
Note: You can directly copy your release build to any system without registering so long as you have correctly setup your assemblies. :)