Make an ActiveX DLL or EXE (2023)

Make an ActiveX DLL or EXE (1) Make an ActiveX DLL or EXE (2) Make an ActiveX DLL or EXE (3)
Home
Search

What's New
Index
Books
Links
Q & A
Newsletter
Banners

Feedback
Tip Jar

C# Helper...



Make an ActiveX DLL or EXE (5)
Make an ActiveX DLL or EXE (6) Make an ActiveX DLL or EXE (7) Make an ActiveX DLL or EXE (8)
Make an ActiveX DLL or EXE (9)
MSDN Visual Basic Community
Make an ActiveX DLL or EXE (10)
TitleMake an ActiveX DLL or EXE
Description
KeywordsActiveX DLL, ActiveX EXE
CategoriesActiveX

    Why?
    Which?
    Making an ActiveX DLL/EXE Project
    Instancing
      Private
      PublicNotCreatable
      SingleUse
      GlobalSingleUse
      MultiUse
      GlobalMultiUse
    Test Projects
    Binding
      Early Binding
      Late Binding

Why?

You make an ActiveX DLL or EXE to allow multiple applications to share the same code. This saves you time because you only need to write the code once. It also lets you devote extra time to debugging the shared code. If you are going to use the code in a lot of different applications, you can perform extra tests to make sure the code works correctly and still save time overall.

Centralizing the code also lets you fix, upgrade, and otherwise modify the shared library relatively easily. You can update the shared DLL/EXE and all of the applications that use it are automatically updated. The Binding section talks more about this.

Which?

ActiveX DLLs and ActiveX EXEs are almost exactly the same in the ways they are built and used. In both cases, you build one or more classes that applications can use to do something. The big difference lies in where they are used.

An ActiveX DLL's code is executed within the main program's address space. It behaves as if the class was created within the main program's code. Because the code lies inside the program's address space, calling methods is very fast.

An ActiveX EXE's code is run in a separate process. When the main program calls an ActiveX EXE's method, the system marshalls the call to translate the parameters into the ActiveX EXE's address space, calls the method, translates the results back into the main program's address space, and returns the result. This is slower than running an ActiveX DLL's method inside the main program's address space.

Because of the difference in speed, an ActiveX DLL is almost always preferable. The reason ActiveX EXEs are useful is they can run on a different computer than the main program while an ActiveX DLL must run on the same computer as the main program.

If you want to build a library of shared routines to save programming and debugging, use an ActiveX DLL because it will give you better performance. Even if you need to distribute several copies of the DLL on different computers, it will probably be worthwhile.

If you want a centralized server library, use an ActiveX EXE. The EXE can sit on a central computer and work directly with that computer's resources. If you need to frequently change how the code works, you can easily change it in one place.

Making an ActiveX DLL/EXE Project

Start a new project and select ActiveX EXE or ActiveX DLL. Initially the project is named Project1 and contains a class named Class1. Change these to meaningful names. The model Microsoft has in mind is a DLL/EXE contains several related classes that each perform related functions. For example, a DLL might contain billing system classes named Customer, Product, and SalesPerson. The Customer class would contain methods for manipulating customer data. In this example, you might change the project name to BillingObjects. You would change Class1's name to Customer and add two more classes named Product and SalesPerson.

Give the class Public functions and methods to perform whatever tasks it should. The main program can only invoke the Public class methods.

Instancing

Set the classes' Instancing properties to determine how the object can be created. In VB6 the allowed values are:

Private

Code outside the DLL/EXE cannot create this object type. Other classes in the DLL/EXE can use this type of class as a helper but the main program cannot use it.

PublicNotCreatable

The main program can use this type of class but cannot create new instances using the New keyword or with CreateObject. In this case, you need to provide some method within the other classes to create the new object and return it to the main program.

SingleUse

The main program can create the object. Every time you create a new object, the system makes a new ActiveX EXE instance to service the object you created. Among other things, if the EXE contains global variables then different objects you create get different copies of the variables. This option is allowed for ActiveX EXEs only.

GlobalSingleUse

Similar to SingleUse except you can invoke the properties and methods of the class as if they were simple global functions. This option is allowed for ActiveX EXEs only. See GlobalMultiUse later for more details.

MultiUse

The main program can create the object. When it does, the system makes an ActiveX DLL/EXE component to handle the object. If you make other objects, the system uses the same ActiveX DLL/EXE component to handle them. This can be a little confusing depending on whether you are building a DLL or EXE and whether an EXE is running on different computers.

If you build an ActiveX DLL, all programs run the DLL code in their own address spaces. That means different objects created in the same program will share the same component server so they could share global variables defined in the DLL. However, if the objects are all freed at the same time, the component server will shut down so any global values will be lost.

The code in the SharedDll directory available for download demonstrates this kind of sharing. The BillingObjects,vbp project contains the project named BillingObjects. This project holds a BAS module holding a public variable named g_TheNumber. This variable is visible to other code in the project but not to a main program using the DLL.

The BillingObjects project also contains a MultiUse class named Customer. This class has Property Let and Property Get procedures that set and get the value of g_TheNumber.

The main program uses two Customer objects like this:


Private m_Customer1 As ObjectPrivate m_Customer2 As ObjectPrivate Sub Form_Load() Set m_Customer1 = _ CreateObject("BillingObjects.Customer") Set m_Customer2 = _ CreateObject("BillingObjects.Customer")End SubPrivate Sub cmdGet_Click() txtTheNumber.Text = m_Customer1.TheNumberEnd SubPrivate Sub cmdSet_Click() m_Customer1.TheNumber = CInt(txtTheNumber.Text) txtTheNumber.Text = ""End Sub

In the DLL project, open the File menu and select Make BillingObjects.dll to build the DLL. Notice how the main program uses the CreateObject function to create its instances of the Customer class. The name of the class is the project's name followed by the class name: BillingObjects.Customer.

Notice also that the program creates the two Customer objects when it starts and it keeps those objects running. That means the component stays running so the objects share the value of g_TheNumber. If you use the Set button to save a value into this variable and then use the Get button to retrieve the value, you should get back the value you saved.

This behavior is what you would expect if you included the DLL's modules directly inside the main program. If you want that behavior, make the DLL MultiUse. If you want each class object to have its own global variables, make the DLL SingleUse. Or better still, move the variables inside the class so each object gets its own variables but you still only need one component instance. That will save some overhead.

Now you're probably saying, "Big deal. I could have shared values a lot more easily with simple global variables." You're right. The interesting thing is any program that uses a shared component server can share the values. Compile the test program and use Windows Explorer to launch two instances of the program. Enter 1234 in one instance and click Set. Then click Get in the other instance. The second program should see the value set by the first.

Note that this sometimes gets messed up and a component server is left running so you may end up with two programs running different component servers.

The ActiveX EXE project in the SharedExe directory demonstrates this sharing using an ActiveX EXE. It's basically the same as the previous example except is uses an ActiveX EXE instead of a DLL. Compile the test program and use Windows Explorer to launch two instances of the program. Enter 1234 in one instance and click Set. Then click Get in the other instance. The second program should see the value set by the first.

GlobalMultiUse

This is similar to MultiUser except the main program can reference methods and properties as if they were globally declared. The code in the GlobalMultiUse directory demonstrates this. The ActiveX EXE code is the same as in the previous example except the Customer class is marked GlobalMultiUse. The main program uses the Customer's TheNumber property procedures like this:


Private Sub cmdGet_Click() ' Implicit use of: ' GlobalBillingObjects.Customer.TheNumber txtTheNumber.Text = TheNumberEnd SubPrivate Sub cmdSet_Click() ' Implicit use of: ' GlobalBillingObjects.Customer.TheNumber TheNumber = CInt(txtTheNumber.Text) txtTheNumber.Text = ""End Sub

This code simply uses the TheNumber procedures as if they were globally declared. When the program invokes one of the methods using this global syntax, it creates an instance of the class to use its methods. It continues to use that instance whenever it needs to execute a global method.

If you explicitly create other instances of the class, you get new object not the global one. As far as I know, there is no way to get a direct reference to the global object instance.

This all seems pretty confusing so I would avoid using GlobalMultiUse and GlobalSingleUse. They let you use a syntax that is more similar to that used by DLLs built in C++ and other languages and that's probably why Microsoft implemented these. They hide the fact that there is an underlying class object, however, so they increase your chances for confusion.

Test Projects

The previous sections glossed over a few details dealing with test projects. After you create your ActiveX DLL project, you can add a test application. Open the File menu, select Add Project, and add a Standard EXE. That project can act as the main program to test your DLL. This is handy because it means you don't need to compile the DLL before you can test it. It also means you don't need to jump back and forth between the DLL and test application projects.

After you have the DLL code working, you can compile it into a DLL file. Then you can create independent applications to use it.

Binding

You can bind your DLL or EXE either at runtime (late binding) or at design time (early binding). When you use early binding, you tell the main program all about the DLL. That lets it do things like provide intellisense for the DLL's methods. It is also faster than late binding.

Early Binding

To use early binding, load the main program, open the Project menu, and select References. Find your DLL in the list and select it. If the DLL project's name is BillingObjects, then look for an entry named BillingObjects. If you have had a couple versions of the project in different locations, you may see more than one entry. Click on one and look at the location displayed near the bottom of the dialog to see if you have the right one. If you can't figure it out, click the Browse button and find the DLL yourself. When you have selected the DLL, click OK.

Now the program can explicitly refer to the classes in the DLL. For example, it could declare and create a Customer object like this:

 Dim customer1 As Customer Set customer1 = New Customer

If you now type "customer1.", intellisense will be able to list the public methods provided by the Customer class. In this example, this is just the TheNumber property procedure.

Early binding has the disadvantage that it imposes more restrictions on the DLL's compatibility. If you change the DLL's methods as they are visible to outside code, the main program will no longer have a correct picture of the DLL. For example, if you add a new Public method to a class, the main program will not know about that method. When you try to create an instance of the class, the system will decide that the program is looking for an incompatible DLL version and will display the message:

Class does not support Automation or does not support expected interface

To fix this, load the main program, open the Project menu, and select References. Deselect the DLL and click OK. Then open the References dialog again and reselect the DLL. Now the program will work again.

Depending on your exact arrangement, you may also get the error:

Type mismatch

To fix this, recompile the main program.

Late Binding

To use late binding, declare references to DLL objects to have type Object. Then use the CreateObject statement to instantiate the objects like this:

 Dim customer1 As Object Set customer1 = CreateObject("BillingObjects.Customer")

This code creates an instance of the Customers class that is defined by the DLL project named BillingObjects. After this the program can use the Public properties and methods of the customer1 object just as if it had declared it using early binding.

Now if you change the DLL's public methods, the compiled executable will still work (if you removed the methods the program uses). The downside with late binding is you don't get intellisense and calling the DLL's methods takes longer than it does with early binding.

FAQs

How to create ActiveX DLL? ›

To create the ActiveX COM Object
  1. Open Visual Basic. ...
  2. Select ActiveX DLL, and click OK.
  3. A window should open called Project1 - Class1 (Code). ...
  4. From the Project menu, click Project1 Properties. ...
  5. In Visual Basic, you define a class to group together methods and properties.
Jun 16, 2017

How do I create an ActiveX EXE component? ›

Open an instance of Visual Basic Choose ActiveX EXE and select Open. Go to the properties of class and change its name property to clsActivexEx. Add a new Form by using Add Form menu item in the project menu. Change the name property of form to frmActivexEx and the caption to "Form From ActiveX Exe".

What is the difference between ActiveX DLL and EXE? ›

One of the main differences between ActiveX EXE and an ActiveX DLL's is that the code is executed within the main program's address space for ActiveX DLL. This is because the code lies inside the program's address space, calling methods and execution of code is very fast.

How to make ActiveX control in C#? ›

Writing an ActiveX Control in . NET
  1. Create an assembly (class library project) that contains an item of type User Control.
  2. Expose an interface for the control.
  3. Embed the user control into a web page.
  4. Transfer data from a web form to the control and display the data on the control.
Apr 8, 2019

Can you make your own DLL? ›

To create a DLL project in Visual Studio 2019

On the menu bar, choose File > New > Project to open the Create a New Project dialog box. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.

How do I create an executable DLL? ›

Simply put, type in "dll_to_exe filename. dll filename.exe" where filename is replaced with the DLL file and the output executable name you want. 32-Bit and 64-Bit DLL are supported.

Is ActiveX a programming language? ›

ActiveX is not a programming language, but rather a set of rules for how applications should share information. Programmers can develop ActiveX controls in a variety of languages, including C, C++, Visual Basic, and Java. An ActiveX control is similar to a Java applet.

How do I register ActiveX control DLL manually? ›

Click Start > All Programs > Accessories and right-click on "Command Prompt" and select "Run as Administrator" OR in the Search box, type CMD and when cmd.exe appears in your results, right-click on cmd.exe and select "Run as administrator" At the command prompt, enter: REGSVR32 "PATH TO THE DLL FILE"

Does Microsoft still support ActiveX? ›

Regarding End of Support for Microsoft Web Browser Control ActiveX - Microsoft Q&A. This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Can a DLL be an exe? ›

A DLL file is not by it self executable, though it may contain executable code. A DLL (Dynamic-Link Library) contains code, data, resources etc. usable by other programs. You need an EXE file for the operating system to execute code within DLL files, like "RUNDLL.

Is ActiveX obsolete? ›

In 2015, Microsoft released Microsoft Edge, the replacement for Internet Explorer with no support for ActiveX, this event marked the end of ActiveX technology in Microsoft's web browser development. Microsoft Edge ships with the "Internet Explorer mode" feature, which supports ActiveX.

Why would you use ActiveX? ›

By using ActiveX controls, developers can implement commonly performed operations across many applications without having to redevelop the code for each instance. ActiveX controls are supported in other ways. One example is the Google Chrome browser, which offers the IE Tab add-in.

How do I assign a macro to an ActiveX control? ›

Assign a Macro to an ActiveX Control Button
  1. Click on the Developer tab.
  2. In the Control group, click on Insert.
  3. In the options that appear, in the ActiveX Controls options, click on the Command Button option.
  4. Click anywhere on the worksheet.
Apr 23, 2020

How do I create a controller code for Visual Studio? ›

To add a controller, in Visual Studio Code right-click the Controllers folder and select New File. When the text box appears, enter CarsController. cs as the new file name. This will add a new C# file that will also open in the code editor.

How do you create a control in visual programming? ›

Building Controls from Other Controls
  1. Choose Project→Add User Control from the main menu.
  2. Type the name of the . vb file that will hold the code for the control, and click OK. ...
  3. Add controls from the Toolbox window just as you would when laying out a form.

How does creating a DLL differ from creating an EXE? ›

Both of these include executable code, however, DLL and EXE operate differently from one another. The EXE will create its own thread and reserve resources for it if you run it. A DLL file, on the other hand, is an in-process server, so you cannot run a DLL file on its own.

What programming language is used in DLL? ›

DLL files use languages like C or C++, although you'll see C++ more often. You can write your own DLLs to run some code you need if you're willing to learn how to do it. It could be valuable to your project and of course it could make you look good in return.

Can you make DLL with Python? ›

Python embedding is supported in CFFI version 1.5, you can create a . dll file which can be used by a Windows C application. If you have a DllMain, you can declare it as "CFFI_DLLEXPORT int __stdcall DllMain(void* hinstDLL, unsigned long fdwReason, void* lpvReserved);" in your header file.

How do I create an executable code? ›

To create an executable, create an Application document (. gcomp), add source files to the document, and build the application into an executable.

How do I create a DLL in notepad? ›

dll - /out: followed by the name of the DLL you want to create.
...
Using the code
  1. Create a new folder in inetpub called "vbc"
  2. Copy the file vbc.exe into it.
  3. Open a Command Prompt window and note the default folder it opens in.
  4. Copy the file vbc. bat into that folder, having amended it if necessary.
Jul 16, 2007

How do I make a script executable? ›

Steps to write and execute a script
  1. Open the terminal. Go to the directory where you want to create your script.
  2. Create a file with .sh extension.
  3. Write the script in the file using an editor.
  4. Make the script executable with command chmod +x <fileName>.
  5. Run the script using ./<fileName>.

What replaced ActiveX? ›

Information. ActiveX was gateway technology that bridged the important gap from desktop to web technologies. Modern browsers like Microsoft Edge and Google Chrome have re-defined the segmentation between content and data controls.

What is ActiveX DLL? ›

Components provide reusable code in the form of objects. A VB6 application that uses a component's code, by creating objects and calling their properties and methods, is referred to as a client. And the DLL that exposes those components is referred as the server.

What apps use ActiveX? ›

Distributing Applications Containing ActiveX Controls
  • Microsoft Chart Control.
  • Microsoft Comm Control.
  • Microsoft DTPicker Control.
  • Microsoft ImageCombo Control.
  • Microsoft ImageList Control.
  • Microsoft Internet Control.
  • Microsoft ListView Control.
  • Microsoft Mail Control (MapiSession, MapiMessage)

How do I register ActiveX DLL in Windows 10? ›

How to register or deregister DLL, OCX and EXE files
  1. To register DLL or OCX files use the command regsvr32. ...
  2. To deregister DLL or OCX files use the command regsvr32 with the /u switch. ...
  3. To register EXE files type the full path and filename and append /regserver.

Can a DLL be used without registering it? ›

Yes, if it does not rely internally on other registered objects.

How do I manually install a DLL? ›

How to Install dll Files on Windows?
  1. Step 1: Download dll File. Open the below-provided link to open DLL-Files official website. ...
  2. Step 2: Extract the Zip dll File. Navigate to the Downloads directory and right-click on the dll zip file. ...
  3. Step 3: Copy the dll File. ...
  4. Step 4: Paste dll File into Destination Folder.

How do I activate ActiveX on Windows 10 64 bit? ›

Use the following instructions to enable or disable ActiveX controls in the Trust Center.
  1. Click File > Options.
  2. Click Trust Center > Trust Center Settings > ActiveX Settings.
  3. Click the options you want, and then click OK.

How do I install ActiveX control? ›

Choose to Allow this operation if prompted. Now, go to your web site. Click "The site might require the following Activex control: Edraw Office Viewer Component from Edraw Limited, Click here to install." on the bar. Click Install officeviewer.

Can a DLL be a Trojan? ›

dll file, a module that assists the DNS client service in the Windows operating system, essentially by caching the Domain Name System (DNS) names requested during a web browsing session. Due to its behavior, the trojan is also referred to as a 'DLL patcher'.

How do I programmatically get the version of a DLL or EXE file? ›

The easiest way is to use the GetFileVersionInfoEx or GetFileVersionInfo API functions.

Can Python Make EXE files? ›

Underneath the GUI is PyInstaller, a terminal based application to create Python executables for Windows, Mac and Linux. Veteran Pythonistas will be familiar with how PyInstaller works, but with auto-py-to-exe any user can easily create a single Python executable for their system.

Is ActiveX a security risk? ›

Signed software can actually give users a false sense of security, and signed ActiveX controls are commonly used by hackers to install malware and spyware from infected or malicious websites.

Is ActiveX malware? ›

Information security experts warn that ActiveX content can be used by intruders, for example, to download malware onto a user's computer.

What browsers still support ActiveX? ›

By default, ActiveX only works on applications that were also made by Microsoft; that includes Internet Explorer, PowerPoint, Excel, Word, etc. However, you can now enable ActiveX on both Google Chrome and Mozilla Firefox, even though this wasn't possible initially. Let's take a look at what you need to do.

Where are ActiveX DLLs stored? ›

ActiveX controls are typically installed as shared files in the Windows System folder. Within InstallMate, this folder is available as Windows\System (32-bit) on the Files and folders project page.

Do people still use ActiveX? ›

ActiveX remains useful to Microsoft users and is included with Windows 10. This is because ActiveX still allows standalone software to receive updates, interface across programs, and enhance functionality.

What is the purpose of ActiveX? ›

ActiveX is a set of object-oriented programming technologies and tools that Microsoft developed for Internet Explorer to facilitate rich media playback. Essentially, Internet Explorer uses the ActiveX software framework to load other applications in the browser.

What is the command to register a DLL? ›

Regsvr32 is a command-line utility to register and unregister OLE controls, such as DLLs and ActiveX controls in the Windows Registry. Regsvr32.exe is installed in the %systemroot%\System32 folder in Windows XP and later versions of Windows.

How do I fix ActiveX control is not registered? ›

On the Developer tab, in the Controls group, click Insert, and then under ActiveX Controls, click More Controls. At the bottom of the More Controls dialog box, click Register Custom.

Is ActiveX deprecated? ›

ActiveX is a deprecated software framework created by Microsoft that adapts its earlier Component Object Model (COM) and Object Linking and Embedding (OLE) technologies for content downloaded from a network, particularly from the World Wide Web.

How to register a DLL in C#? ›

Register a DLL using regsvr32.exe
  1. RegSvr32.exe has the following command-line options: Regsvr32 [/u] [/n] [/i[:cmdline]] dllname. - /u - Unregister server. ...
  2. For example, to manually register the Sample.ocx ActiveX control, you would type the following at the command prompt: C:\Regsvr32.exe Sample.ocx.
Nov 12, 2020

References

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated: 10/20/2023

Views: 5810

Rating: 4.1 / 5 (42 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.