Beginning VB 6For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
They serve two entirely different purposes. A dynamic link library project allows you to create your own type library. You can create your own library of classes in a project, compile it to a dll, then reference the dll from other projects to use the functionality (call methods and properties, etc.) of the classes your dll contains. The main advantage of using a dll is code reuseability. Compile your classes into a dll, then reference that one dll from as many apps as you like. The main disadvantage of COM dll's is what folks call "dll hell", having the dll file on your system in the wrong version or in the wrong place so that apps relying on its functionality can't find it or use it.
An exe project simply creates a standard WIN32 portable executable (pe) file that anyone running Windows can open. So for example, you could create a class library (dll), compile it, create an exe, reference your class library in the exe, compile the exe, then run the exe application, and the exe could use the functionality stored in the dll.
your description of the ActiveX dll is correct, but the OP question was about an ActiveX exe, not a standard exe.
An ActiveX exe acts in a way like a standard exe, but it needs to be registered to run (like all other ActiveX objects), and like an ActiveX dll it exposes classes that clients can create and use.
There is a big differences between ActiveX dll and exe: the dll is an "in-proc" server, that is it runs in the same memory space of the main application, unlike the exe, that is a "out-proc" server, and therefore runs in its own memory space (it is basically another application running, in short) For this reason it is much faster to call a dll, because there is no marshalling of data between two processes.
Typically, ActiveX exe are used to create windows "servers", that can run locally or remotely in another computer. Incidentally, ActiveX exe are also used by VB programmers to create multi-threaded applications (see the Coffe Machine example in the VB documentation), because a ActiveX exe class created using CeateObject runs in its own thread of execution.
COM Components (either AcitveX dll or ActiveX exe) provide a way to decouple and deploy applications in a way allows for reuse of these components. Additionally, COM allows you to deploy components on different machines for distributed use.
For example, if you have an application server and a number of client machines you could write an ActiveX dll which you would install in a COM+ application on the application server which could then be accessed by all the client machines. This is often done to centralize business or data logic. Alternatively, if you didn't want to use COM+, you would write an ActiveX exe and use DCOM directly (which COM+ uses behind the scenes) for the client apps to be able to access the ActiveX exe.
Now days, it is not as common as it used to be in enterprise apps to use ActiveX exe's for the purpose of distributing since most of the time the cross machine work is done using COM+. However, there are still many reasons to use ActiveX exe's: One is to automate a stand-alone application so it's features can be directly used by a client app. Another is to allow one process to spawn other processes to be able to do work that runs asynchronously. Since you cannot do multi-threaded work in VB6, this allows you to control a number of processes from a single controller app to achieve a similar result.
ActiveX dlls are often used by a GUI form-based front end to provide the business layer in an n-tier application. For example, you could have a class that calculates tax. Once you have it working well, you want to use it for any application you write. By placing this class into its own ActiveX dll and registering it on a machine, any application that needs to use this code will be able to do so (as long as you write the code for it to do so).
In my use, almost all logic that is not directly GUI based is in an ActiveX dll.