Don’t pass Private objects to client applications

Don’t pass Private objects to client applications

Under some circumstances, an ActiveX DLL can pass private objects to its client application, for example a reference to a control that belongs to a form in the DLL. While this approach can be useful, and can work under some circumstances, you should absolutely avoid avoid to do so, because it might be the cause of subtle GPFs in production code.

The reason for such fatal errors is that a reference to a Private object doesn’t keep the DLL alive. In fact, COM can’t determine that the main application has a reference to an object in the DLL if the object is private, and releases the DLL if the application has explicitly or implicitly set to Nothing all the other references to (Public) objects defined in the DLL. When the application eventually uses the object variable (which is now pointing to a deallocated block of memory) the fatal error occurs.

Please note that such errors are really hard to find and debug, because VB typically helds an inactive ActiveX DLL in memory for about 10 minutes. Thus the bug can or cannot occurs, depending on whether the reference to the Private variable is used while the DLL is still in memory. Also note that the same rule applies to other types of in-process ActiveX components, such as a UserControl that directly exposes one of its constituent controls to the main application.While it is a good programming habit not to expose Private objects to the outside world, there is a safe technique for working around this problem: you just must ensure that the DLL is never released. This can be done by having a Public global variable that always points to a (Public) object in the DLL, and explicitly destroying all references to Private object before such global variable is automatically set to Nothing when the main client application terminates.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing