|
|
|
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. |
Click here to copy the following block | Private Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As _ Long, ByVal lpfn As Long, ByVal lParam As Long) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal _ hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Dim m_ClientIsInterpreted As Boolean
Function ClientIsInterpreted() As Boolean EnumThreadWindows App.ThreadID, AddressOf EnumThreadWindows_CBK, 0 ClientIsInterpreted = m_ClientIsInterpreted End Function
Public 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
length = GetClassName(hWnd, buffer, Len(buffer)) windowClass = Left$(buffer, length) If windowClass = "IDEOwner" Then m_ClientIsInterpreted = True EnumThreadWindows_CBK = False Else EnumThreadWindows_CBK = True End If End Function |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
 |

|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|