Determine whether an ActiveX DLL is being used by an interpreted program

While determine whether the current program is running as interpreted or compiled code is relatively easy, determine whether an ActiveX DLL is serving an interpreted or compiled application is a bit more difficult. This information might be useful to disable or enable special features, or just to prevent from other programmers to reuse the code in your own DLL.

The following solution is based on the EnumThreadWindows API function. This API function enumerates all the windows that belong to a given thread, and the code below uses it to check whether there is a window of class “IDEOwner” in the same thread as the DLL. If this is the case, it means that the DLL is running in the same thread as the Visual Basic IDE, hence its client is an interpreted program.

This function doesn’t check for other possible interpreted clients, but you can do that simply by checking for additional window class names in the EnumThreadWindows routine.

Private Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As _    Long, ByVal lpfn As Long, ByVal lParam As Long) As LongPrivate Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal _    hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long' this variable is shared between the two routines belowDim m_ClientIsInterpreted As Boolean' return True if the client application of this DLL' is an interpreted Visual Basic program running in the IDE'' NOTE: this code is meant to be inserted in a BAS module'       inside an ActiveX DLL projectFunction ClientIsInterpreted() As Boolean    EnumThreadWindows App.ThreadID, AddressOf EnumThreadWindows_CBK, 0    ClientIsInterpreted = m_ClientIsInterpretedEnd Function' this is a callback function that is executed for each' window in the same thead as the DLLPublic Function EnumThreadWindows_CBK(ByVal hWnd As Long, _    ByVal lParam As Long) As Boolean    Dim buffer As String * 512    Dim length As Long    Dim windowClass As String    ' get the class name of this window        length = GetClassName(hWnd, buffer, Len(buffer))    windowClass = Left$(buffer, length)        If windowClass = "IDEOwner" Then        ' this is the main VB IDE window, therefore        ' the client application is interpreted        m_ClientIsInterpreted = True        ' return False to stop evaluation        EnumThreadWindows_CBK = False    Else        ' return True to continue enumeration        EnumThreadWindows_CBK = True    End IfEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS