Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1528

Registry Free Object Instantiation using DirectCOM & RC6

$
0
0
There are a few variations of this kind of reg-free "bootstrapping" module already circulating, but I wanted to write one that was highly commented in the hope that it will help some newcomers better understand how to write their VB6/RC6 apps in a way that works without requiring their DLLs to be registered, and also how to package their app & DLLs so that everything will work smoothly when deployed on a user's computer without registration.

Source Code - Download here: MRC6Base.zip

NOTE: This is a work in progress - if there are any parts of the code or comments that you still find confusing, please ask! I'll try my best to clarify and update the comments so that we have a comprehensive document that will be easily understood by newcomers to RC6.

Things are described in much more detail in the module comments, so I suggest you read them all. Here are the basics:

THE PRIMARY GOAL OF THIS MODULE is to be universal and foundational code for VB6 apps using DirectCOM.dll and RC6.dll to instantiate ActiveX objects without requiring the use of regsvr32/installers on your application's end users' computers. This approach will be called "DirectCOM reg-free" or simply "reg-free" for the rest of this post.

By "Universal" I mean that this module should be added to EVERY VB6/RC6 project.
By "Foundational" I mean that this module should be the FIRST THING that you add to every project you create that will be using RC6/DirectCOM reg-free.

TO USE THIS MODULE

When you start writing a new app, add MRC6Base.bas to your project via the Project > Add Module menu.
Next, add a reference to RC6.dll via the Project > References menu.

You will now have everything you need to start writing a reg-free VB6/RC6 application. The main thing to understand is that there are now 5 ways to instantiate new objects in your code instead of only the regular 2 ways (New keyword and CreateObject function). The choice of which method to use depends on the type of object you want to create.

Using the New Keyword
Use the built-in VB6 New keyword to instantiate objects that you know will be registered on the user's computer, or that are built-in to the VB6 runtime or STDOLE. For example, VB6 Collections, StdFont objects, StdPicture objects, etc... should always be instantiated via the New keyword.

Using the CreateObject Method
Use the built-in VB6 CreateObject method to instantiate objects that you know will be registered on the end user's computer late-bound. This would include things like Excel.Application, Word.Application, Shell objects, etc...

Using the New_C Method
Use the New_C method to instantiate all RC6 objects excluding Cairo objects. This instantiation will occur without touching the registry, so RC6.dll does not need to be registered on your end user's computer. Example:

Code:

Dim RS As RC6.cRecordset

Set RS = New_C.Recordset    ' Instead of the more familiar "Set RS = New Recordset" which would require a trip to the registry

Using the Cairo Method
Use the Cairo method to create new RC6 Cairo objects (amongst other Cairo features). This instantiation will occur without touching the registry. For example, to create a new image surface to draw against:

Code:

Dim Srf As RC6.cCairoSurface

Set Srf = Cairo.CreateSurface(100, 100)  ' Create  100x100 pixels image surface and store the reference in the Srf variable.

Using the CreateObjectRegfree Method
Use the CreateObjectRegfree method to create objects from DLLs that you will distribute with your application (that is, DLLs that aren't distributed by Microsoft with Windows), but that you don't want to register on the user's computer. For example, if you have created your own DLL called MyDll.dll with a class called MyClass, and a method call MySub, you can use it reg-free as follows (make sure you have added a reference to MyDll.dll in the VB6 Project > References menu):

Code:

Dim MC As MyDll.MyClass

Set MC = CreateObjectRegfree("MyDll.dll", "MyClass")

MC.MySub

If you stick to the above rules when writing your code, you will be able to distribute your application and all related DLLs without requiring the DLLs to be registered on your end user's computer.

Packaging & Distributing Your Application

This topic is also discussed in more detail in the source comments, but the basics are:

Your main application folder should contain the following:

  • The EXE that your users will launch to use your app.
  • A folder called System.
  • Other folders that you want to include with your app, such as a Help (for your documentation).


The System folder should contain the following:

  • RC6.dll (available from t
  • cairo_sqlite.dll
  • DirectCOM.dll
  • RC6Widgets.dll (optional - only needed for apps that use RC6 Forms instead of VB6 Forms).
  • Any of your own DLLs that your app references.
  • Any satellite/helper EXEs that your main app shells out to for any purpose.
  • Any third-party DLLs that your main app references, and that aren't already distributed by Microsoft with Windows.
  • A folder named RPCDlls - this is optional, and only needed for client-server applications that use remote procedure calls (RPC) with the RC6 cRpcListener and cRpcConnection classes.


Your main application folder can then be compressed into a ZIP archive, or packaged into a self-extracting executable for distribution to end users. Users can extract the contents anywhere they like, and launch the main application EXE to start using your software immediately - no registration of components required.

I hope this code proves useful to someone out there. Questions and comments are always welcome!
Attached Files

Viewing all articles
Browse latest Browse all 1528

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>