Results 1 to 40 of 41

Thread: Registry Free Object Instantiation using DirectCOM & RC6

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,891

    Registry Free Object Instantiation using DirectCOM & RC6

    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
    Now includes a demo App, DLL, and RPC DLL, bug-fixes and uses the latest RC6.dll

    Latest Version Updated September 3, 2024 - Download here:

    Rc6RegFree7.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 MRegFree.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.

    Creating Objects Using the VB6 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.

    Creating Objects Using the VB6 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...

    Creating Objects Using the RC6 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    ' Creates an RC6.cRecordset object instance in the RS variable without touching the registry. Use this instead of the more familiar "Set RS = New Recordset" approach (which would require a trip to the registry).
    Creating Objects Using the RC6 Cairo Method
    Use the Cairo method to create new RC6 Cairo objects (as well as use all other Cairo features). Instantiating Cairo objects in this way will will not touch the registry, so RC6.dll does not need to be registered on yur end user's computer.

    For example, to create a new image surface to draw against:

    Code:
    Dim Srf As RC6.cCairoSurface
    
    Set Srf = Cairo.CreateSurface(100, 100)  ' Creates a ne RC6.cCairoSurface instance (100x100 pixels) in the Srf variable without touching the registry.
    Creating Objects Using the mRegFree 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") ' Creates an instance of MyDll.MyClass in the variable named MC without touching the registry.
    
    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 registering the DLLs on your end user's computer. This makes it possible to distribute your app without an installer if you like (for example, in a ZIP archive).

    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 that will include the RC6 DLLs and any other DLLs used by your app.
    • Other folders that you want to include with your app, such as a Help (for your documentation).


    The System sub-folder should contain the following:

    • RC6.dll (available at www.vbrichclient.com)
    • cairo_sqlite.dll (available at www.vbrichclient.com)
    • DirectCOM.dll (available at www.vbrichclient.com)
    • RC6Widgets.dll (optional - only needed for apps that use RC6 Forms instead of VB6 Forms - available at www.vbrichclient.com).
    • 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. For example, Chilkat's DLLs.
    • 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, comments, an criticisms are always welcome.
    Last edited by jpbro; Oct 15th, 2024 at 02:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width